Convert images to different format only if size is greater..

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
timbrewolf
Posts: 2
Joined: 2012-01-05T14:38:06-07:00
Authentication code: 8675308

Convert images to different format only if size is greater..

Post by timbrewolf »

Hey everyone - I've seen ImageMagick before, but have a specific project I'm struggling to find a solution for and this seems as close as I have gotten.

I have 10,000 files in a folder, for example - CMYK TIFF that I want to convert to PNG. However, I don't want to convert all of them, only ones that are larger than 1000pixel on either height or width.

My first thought was that I could do this with the -resize 1000^< (windows user). However, even if that kinda works, it ends up resizing the image and I don't really want to resize the image, I just want to convert it.

I have searched through the forums for skipping, ignoring, and such but I can only find the ability to resize to a specific size, not just ignoring files of a smaller size. Any help would be greatly appreciated!

TW
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert images to different format only if size is great

Post by fmw42 »

I think you will have to write a script (Bat file) to loop over all your images, compute the image sizes as variables using -format "%w" and -format "%h" and use a conditional test on the image sizes to determine if you want to convert them or skip them.

See http://www.imagemagick.org/Usage/windows/ as I am not a windows user and can only show you how to do it in Unix/IM syntax.
timbrewolf
Posts: 2
Joined: 2012-01-05T14:38:06-07:00
Authentication code: 8675308

Re: Convert images to different format only if size is great

Post by timbrewolf »

Wow thanks for the super-quick reply.

I hadn't thought of that, but you're right - since .bat files will allow integer variables. I always forget that.

If I'm able to write that, I'll come back and post it if it can help anyone else.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Convert images to different format only if size is great

Post by Bonzo »

There might be a batch file on my site that will get you started: http://www.rubblewebs.co.uk/imagemagick/batch.php
Post Reply