When you are working on a social campaign, like facebook or pof ads, you will find yourself having to resize picture quite often, since many of the images you find will be a lot bigger.
Have you been doing these manually, or have you been doing this in bulk ? You could potentially save quite a bit of them if you automated the resizing part of your campaign creation, allowing for more time to look for pictures for your ad.
Here is a simple script I use often when I need to resize a whole bunch of image to a specific size; I am a LAMP guy and this script uses the “convert” command on Linux.
| php | | copy code | | ? |
| 01 | <?php |
| 02 | |
| 03 | $directory = "/home/username/toberesized"; |
| 04 | $resizedDirectory = "/home/username/toberesized/resized"; |
| 05 | |
| 06 | $handle = opendir($directory); |
| 07 | |
| 08 | /* This is the correct way to loop over the directory. */ |
| 09 | while (false !== ($file = readdir($handle))) {
|
| 10 | if (preg_match("/jpg$/", $file)) {
|
| 11 | |
| 12 | `convert -geometry 120x120 $directory/$file $resizedDirectory/$file`; |
| 13 | } |
| 14 | |
| 15 | ?> |
| 16 |
Here is how to use this script
- Save this code as imageResize.php.
- On your linux server, upload all of your images to a specific folder, for example /home/username/toberesized
- Within this folder, created a subfolder named “resized”
- Also, to change the target image size, simply change the 120×120 to your desired image size.
Once that is done, simply update the following lines in the code, to tell the scrip where your images are located:
$directory = “/home/username/toberesized”;
$resizedDirectory = “/home/username/toberesized/resized”;
Once this is done, simply run this imageResize.php script with this command: php imageResize.
You will then see all of your original image, resized to the specific size with the same name, under the “resized” folder you specified.
to success,
September 28th, 2010
kazu
Posted in
Tags: 














