Web Hosting Talk







View Full Version : What command to recursively resize images...


ThatScriptGuy
10-19-2006, 11:56 AM
I need to issue a command via SSH to resize all images to 63% of their original size...

Running linux with GD2 installed...Is this possible?
Kevin

Saeven
10-20-2006, 12:43 PM
Definitely possible.

Your first order of business is to make the script recursively open directories, and locate appropriate file extensions. You'll make extensive use of the closedir, readdir and opendir functions.

Then manipulate the images with these functions:
http://ca3.php.net/manual/en/function.getimagesize.php
http://ca3.php.net/manual/en/function.imagecopyresized.php
http://ca3.php.net/imagegd

Good luck.
Alex

maxymizer
10-20-2006, 04:26 PM
I think he asked for SSH command, not advice on how to make a script of some kind..
I don't know of any such command, but just maybe ImageMagick supports something like that.

ThatScriptGuy
10-21-2006, 02:29 PM
Yup..I'd prefer something via SSH (I know I'd have to find -f all the jpgs and then execute the command to resize them but I dunno what that command is...)

PHP+GD is having problems resizing these very large images, so I'm hoping that an SSH command will do the trick...
Kevin

Saeven
10-21-2006, 02:42 PM
I assumed that you wanted a script to be run via SSH given that this was in the programming forums..

If you know of a command that can resize pictures (I don't), you could indeed as suggested, use find.

find . -name '*.png' -type f -exec fileresizecommand {} \; -print

PHP+GD is having problems resizing these very large imagesIf you execute a single shell script on each image, it will likely shave you lots of memory instead of having PHP resize all the pictures in one stroke. I've resized massive files using GD however, size and rapidity is only function of your memory limit, and your processor's power. It wouldn't be PHP+GD having problems, but instead your computer or the way it was setup.

foobic
10-21-2006, 09:06 PM
Don't know about GD, but assuming you also have imagemagick installed, this to resize all jpgs to 63%:
find . -name \*.jpg -exec convert {} -resize 63% {} \;
but if you have lots of different sized large images a better idea might be to resize down only those above a certain size:
find . -name \*.jpg -exec convert -size '800x600' {} -resize '>800x600' {} \;
(the first "-size" saves memory by not loading big images at full resolution, the "-resize >" does a resize only if the existing image is larger)
HTH

ThatScriptGuy
10-22-2006, 12:26 PM
Thanks foobic..
Going to install imagemagick and give that a shot...
Kevin