Page 1 of 1
Script request: move a image file to dimension subdirectory
Posted: 10 Feb 2023 17:23
by obscure2
Hi,
i would need a script that allows me to do the following thing:
I have a folder containing many images - for exaple paris photos -
Code: Select all
- Paris photo
-- image1 (2000x2000px)
-- image2 (1920x1080px)
-- image3 (2500x2000px)
-- ...
these images are of different sizes, is it possible to move into subdirectories with the dimension name?
this should be the result:
Code: Select all
- Paris photo
-- 2000x2000
-- image1, image5, ...
-- 1920x1080
-- image2, ...
-- 2500x2000
-- image3, image8, ...
It's possible to do it?
Re: Script request: move a image file to dimension subdirectory
Posted: 10 Feb 2023 18:14
by highend
Code: Select all
$images = quicksearch("/types={:Image} /n");
end (!$images), "No image file(s) in current folder, aborted!";
$cntImages = gettoken($images, "count", <crlf>);
while ($i++ < $cntImages) {
$image = gettoken($images, $i, <crlf>);
$dimensions = replace(property("#image.dimensions", $image), " ");
if ($dimensions) {
$dst = <curpath> . "\" . $dimensions;
moveto $dst, $image, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
}
}
Re: Script request: move a image file to dimension subdirectory
Posted: 10 Feb 2023 19:57
by obscure2
First of all thank you for your reply.
The script works fine.
However it is very slow and in a folder with 1500 photos I don't know how long it can take.
Is there a way to speed it up?
Otherwise it does exactly what needs: check the size, create the folder and move the file inside.
Fantastic!
Thank you.
Re: Script request: move a image file to dimension subdirectory
Posted: 10 Feb 2023 20:44
by highend
Code: Select all
$images = quicksearch("/types={:Image} /n");
end (!$images), "No image file(s) in current folder, aborted!";
$data = "";
foreach($image, $images, <crlf>, "e") {
$dimensions = replace(property("#image.dimensions", $image), " ");
if ($dimensions) { $data .= $dimensions . "|" . $image . <crlf>; }
}
$data = trim($data, <crlf>);
if ($data) {
// Get first entry and its size, match all others, remove them...
while (true) {
if (!$data) { break; }
$size = gettoken(gettoken($data, 1, <crlf>), 1, "|");
$toMove = regexmatches($data, "^" . $size . "\|.+?(?=\r?\n|$)", <crlf>);
$toMove = regexreplace($toMove, "^.+?\|"); // Remove size again
$data = regexreplace($data, "^" . $size . "\|.+?(\r?\n|$)");
moveto <curpath> . "\" . $size, $toMove, , 2, 2, 2, 1, 0, 0, 1, 0, 0;
wait 1;
}
}
Re: Script request: move a image file to dimension subdirectory
Posted: 11 Feb 2023 11:22
by obscure2
With this new version the times have been reduced to a third.
3x speed.
Thanks.