Script request: move a image file to dimension subdirectory

Discuss and share scripts and script files...
Post Reply
obscure2
Posts: 3
Joined: 12 Sep 2018 09:35

Script request: move a image file to dimension subdirectory

Post 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?

highend
Posts: 13330
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script request: move a image file to dimension subdirectory

Post 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;
        }
    }
One of my scripts helped you out? Please donate via Paypal

obscure2
Posts: 3
Joined: 12 Sep 2018 09:35

Re: Script request: move a image file to dimension subdirectory

Post 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.

highend
Posts: 13330
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script request: move a image file to dimension subdirectory

Post 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;
        }
    }
One of my scripts helped you out? Please donate via Paypal

obscure2
Posts: 3
Joined: 12 Sep 2018 09:35

Re: Script request: move a image file to dimension subdirectory

Post by obscure2 »

With this new version the times have been reduced to a third.
3x speed. :appl: :appl:
Thanks.

Post Reply