I have this class in PHP that when resized resizes the images contained in a folder. If you notice, the resizing is triggered by these instructions, one for each desired size.
resize_and_crop('banner.jpg', 'banner_100x100.jpg', 100, 100);
resize_and_crop('banner.jpg', 'banner_200x100.jpg', 200, 100);
resize_and_crop('banner.jpg', 'banner_200x300.jpg', 200, 300);
The full function is in pastebin and it perfectly resizes the original image in 3 copies, each of a different size as determined by the use of the resize_and_crop()
function. I'll put the file to run inside the images folder, so it does not need paths.
Note that function
waits for 4 parameters:
- current image name
- new image name
- width (width)
- height (height)
Question: how to loop all images in this folder and within this loop
apply the resize_and_crop()
function to each of the returned images?
// RESIZE AN IMAGE PROPORTIONALLY AND CROP TO THE CENTER
function resize_and_crop($original_image_url, $thumb_image_url, $thumb_w, $thumb_h, $quality = 100)
{
// ACQUIRE THE ORIGINAL IMAGE: http://php.net/manual/en/function.imagecreatefromjpeg.php
$original = imagecreatefromjpeg($original_image_url);
if (!$original) return FALSE;
// GET ORIGINAL IMAGE DIMENSIONS
list($original_w, $original_h) = getimagesize($original_image_url);
// RESIZE IMAGE AND PRESERVE PROPORTIONS
$thumb_w_resize = $thumb_w;
$thumb_h_resize = $thumb_h;
if ($original_w > $original_h) ...
This is just a piece of the function that appears complete in the external link.