Resize all images with specific res in folder

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Resize all images with specific res in folder

Post by Rye »

So let's say I have about 4000~+ images in a folder, all of different resolutions.

The task now is to:
1. Find all images with resolution of 256x384 inside the current folder
2. Resize them to 322x480
(if you are fixed on certain image type, let's assume png is the one for the sake of argument)

Is this possible with image Magic and Dos
(also another approach in linux would also be good, having both ways is always good)
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize all images with specific res in folder

Post by snibgo »

"Resolution" normally means dots per inch (or centimetre etc), but I assume you mean width and height, in pixels.

One method: loop through all the images. For each image, if it is 256x384, resize it.

Most of this is simple scripting, not specific to ImageMagick.

For getting the width and height, I use this Windows snippet ...

Code: Select all

FOR /F "usebackq" %%L IN (`%IM%identify -format "WW=%%w\nHH=%%h" %SRC%`) DO set %%L
... where %SRC% is the filename.
It could be more complex, directly comparing width and height to 256 and 384, returning 0 or 1 (meaning whether to do the resize), eg with identify -format "%[fx:w == 256 && h == 384]". See http://www.imagemagick.org/script/escape.php and http://www.imagemagick.org/script/fx.php .
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Resize all images with specific res in folder

Post by Rye »

I seem to have trouble understanding this one.

Lets say I have 1 png in the same folder with said resolution.

What do I have to add to your script in order for it to work (as it seems to do nothing as of yet... maybe I have to adjust the SRC ?)
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply