OS X: batch processing different size images by taking fixed cm off width and height

I have a whole bunch of images as patterns for clothing. In order to get them correct for processing different folders need to be scaled down by different amounts. Eg one folder needs all images (approx 30) reduced in size by 2.5cm and 2.7 height. Another folder needs each image reduced by 2cm width and 3 cm height. Etc etc. Not all the images in the folder are the same size, so it’s NOT a fixed percentage. We can convert those to pixels if needed (some folders are 250 DPI and some are 300 DPI).

Have checked Lightroom and various solutions on the App store including Easy Batch Photo and XnView. None of these allow this type of rescaling, they only allow a fixed percentage scaling, not scaling by set pixels / cm off each image. Anyone got a solution? I’m fine with buying an App if it’s reasonable, or using a command line tool. Maybe Image Magick can do this or can it be done with Automator actions or Apple Script?

Any ideas ?

Update: Ok also tried photoshop actions, you can change canvas size relative to original, but not image scaling relative to original, so thats no good. And automator doesn’t have this type of scaling, only percentage or fixed size. No go there either.

What format are these images? Most images don’t have centimeter (or inch) measurements at all.

And why do you want to remove a fixed number of centimeters from each image? Wouldn’t the more logical operation be to convert each of them to a fixed number of centimeters? Or, if they’re all starting off at the same number of centimeters, couldn’t you just as well scale them by a fixed percentage?

Install Imagemagik. It can do everything you want (and more). You will probably need to create a simple shell script to drive it. But in general, this sort of thing is grist for the mill for this system.

or if you want a standalone installer package

Chronos, almost any image type can have a DPI assigned. JPG images can have DPI settings so you can convert that into pixels per cm then do the scaling this way. As for why, thats not important, it’s not logical but thats the scaling we need to do, fixed cm off each image regardless of image size, NOT a fixed percentage off each one.

Francis, thanks for the Image Magick suggestion, the docs are kind of “un-intuitive” got any lead for how to get started on this type of size conversion?

How are your Unix chops?

Imagemagik is really a huge Swiss Army knife of a beast that does a ridiculous amount of stuff. But it does it all from the command line. You can describe almost any image processing workflow to it. All in one command. Then you simply apply this command to all your files, which is a as simple a a one line shell command.

Where to start depends on how comfortable you are with this as a general starting point.

yeah I’ve done some bash scripting at various stages. However from what I can see there is no such resize command in image magick. I’d have to read the current image dimensions into bash script variables, subtract the desired amounts and then give image magick a fixed size output.

http://www.imagemagick.org/Usage/resize/

To add - what is the actual final requirement? DO you need a single fixed DPI and thus size in pixels?

Just getting an image to be resampled to a given size in pixels is easy:

convert file.jpg -resize 640x480 fixed.jpg

will convert file.jpg to a a new image of size 640x480 pixels. It gets a little messy of your images are not the same aspect ratio - Imagemagik will attempt to do the most sensible thing and gives you lots of flexibility as well (for instance let it resize one dimension to the defined size, and let the other one float to the correct size to preserve the aspect ratio.)

You could go something like



foreach i(*.jpg)
convert $i -resize 640x480 ../new_images/$i
end


to convert all the images in one folder and stick the converted output in another folder Something more sophisticated might be more use.
ETA - Ah cross posting.

Can you describe the exact set of requirements? But it sounds as if you know enough to get it working.

It sounds to me like he wants to resize images of different sizes by a fixed number of pixels. So, if he were taking 100 pixels off each dimension, he wants a 1000x800 to become 900x700. A 1500x1000 to become a 1400x900. Is that correct coremelt? If so, I wonder why you want something like this (ETA-ok, I see, it’s for some clothing pattern software or something. I’m unclear why it’s not specified by a fixed size, can you explain the exact specs and what you have?), but, more importantly, you have to realize that your aspect ratio changes, so a 1000x800 won’t become a 900x700 without either some cropping or distorting the image slightly (well, the slightness depends on you sizes are and how much you’re shrinking.)

‘Taking x cm/pixels off’ implies cropping, not resizing, but that doesn’t appear to be the OPs intent. I think that caused a bit of confusion up there in the thread.

I am not clear at all what OP is trying to do here, but any of the reasonable guesses in this thread would be super easy to accomplish using AppleScript and photoshop.

The intent was taking off fixed cm off each image, so yes fixed pixels, eg for 2.5cm width off and 2.7 cm height it meant reducing each image by 295 pixels width and 319 high at 300 DPI. And I mean rescale that many pixels down, not crop. And yes the images are different resolutions so I can’t use a fixed percentage reduction which is easy.

And no Photoshop cannot do this, you can change the canvas size by a relative amount and make that into an action which can be batch processed (eg cropping). You cannot do the same with image resize, because image resize does not let you enter a relative amount for width and height which you can make an action. And yes I’m fully aware this will distort the original image (not keep aspect ratio), thats the intent.

Do you need to change any pixels at all, or would it work to just change the DPI settings?

You can’t do it as an action in Photoshop but you sure can AppleScript that and trigger it from photoshop or run it as a droplet.

The way he’s describing it, the pixels would need to change, as aspect ratio will get altered after the resize, and DPI will not alter aspect ratio. For an extreme example, if he’s he’s got a 3x2 photo and wants to take an inch off each dimension, he want’s to make it a 2x1 and have the image stretched to fit along one dimension. If he has an 8x10, it’s less extreme as a 7x9, but still needs to be stretched to fit along one dimension, as he wants to retain all the pixel information and not crop anything out.

Or, basically, he wants something like:

convert Photo (Xwidth,Yheight) to Photo (Xwidth-2.5cm, Yheight-2.7 cm), do not constrain for aspect ratio. If the photo was originally 10cm x 10cm, he wants an output photo of 7.5cm x 7.3 cm, with the pixels stretched or shrunk as needed.


man sips

It’s build in and probably does everything you need it to do.

I believe Graphicconverter can do resize and crop via it’s scripting language, and possibly AppleScript.

I’m not trying to argue with what you’re doing, just trying to gain insight, as it does sound remotely possible that you are still trying to pursue a possibly very complex path to a goal that might be simpler than it first seemed to be*.

You’ve sorted your images into different folders depending on how much they need to be reduced, then you’re going to resize them differently for each folder… to what eventual goal? Are you hoping to end up with uniformly-sized images (or at least, images that all fit within a uniform frame?). If so, the task can probably be expressed much more simply - because ‘resize and constrain to size X, regardless original size’ is a common batch processing function in many different graphics suites.

I hope you will receive this inquiry in the spirit intended. Just trying to understand your expected outcome in case there is a simpler, more elegant solution.

*I once saw someone begin to try to calculate the approximate number of hours in a year by adding up the number of days in each different month…

Why can’t you just use Preview?