Jackson Jackson - 1 year ago 102
PHP Question

PHP: resize all the images in a directory using imagick?

I have a folder with 100's of images in it. I need to resize all the images using


for a single image I can run:

exec("/usr/bin/convert images/image-name.jpg -resize 550x413 images/image-name.jpg");

But how would i go about doing the same thing with all the images?

is there any foreach loop function that I could use?

Any help would be appreciated.

Thanks in advance.

Answer Source

You can load all images in array then execute your method in foreach loop. To load all images in specific array you can use the following command:

$images_array = glob($dir.'*.jpg');
foreach ($images_array as $item) {
    //your code goes here 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download