Page 1 of 1

Auto mogrify a batch of images in a folder

Posted: 2013-10-02T18:50:33-07:00
by Floopty
Hi -

Hoping someone can really help me... I have users on a WordPress site that upload jpg images, which all go to a certain directory. These images can range from 10k to 10MB. I need this folder of images to be a small and semi-consistent file size for web viewing purposes, so I don't eat up bandwidth and storage on my server. Can someone please shed some light on how to make this happen. I want to use the mogrify command and overwrite the larger file in place (and not affect the ones that have already been saved to the smaller size). I would also like this script to auto-run if possible, then I could "set it and forget it" (that would be sweet!) Thanks in advance

(my apache server has ImageMagick installed and running)

Re: Auto mogrify a batch of images in a folder

Posted: 2013-10-02T19:15:28-07:00
by fmw42
I would not suggest you try to auto-run a script in one directory as it will process each image over an over again.

I would suggest you upload to one folder, use chron or some other mechanism to detect when there is a new file and then process the folder with mogrify and put the processed images into another directory that you would use to collect all the processed images. Then delete all the images in the upload folder.

IM has no means of auto-run. You will have to build a shell script with the mogrify command in it and launch it with something like chron.

Make two folders: uploadimages and processedimages

The script commands would then be the following:

cd fullpath2/uploadimages
mogrify -path fullpath2/processedimages -format jpg -resize .... *.jpg
rm *.jpg

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/script/comma ... p#geometry

Re: Auto mogrify a batch of images in a folder

Posted: 2013-10-02T19:44:53-07:00
by Floopty
First off, thank you very much for your detailed reply. Unfortunately, files uploaded to this specific directory need to stay in this directory to view them properly (it's by the design of this particular plug-in)... because of this, do you think I can do the following: Have something like cron detect only new files added to this directory, then make a copy of this file to a temporary directory where Imagemagick would resize, then move and replace the file in the original directory? Do you think this is possible?

or scenario 2: only copy files over a certain file size to another directory, process, then move back & replace?

Thanks

Re: Auto mogrify a batch of images in a folder

Posted: 2013-10-02T20:25:50-07:00
by fmw42
I do not know enough about chron.

But the rest could be done in shell script with shell commands and IM commands.

Re: Auto mogrify a batch of images in a folder

Posted: 2013-10-02T20:52:03-07:00
by Floopty
thanks for your help... and nice work on all of your scripts.