I would like to call a function inside another function in order to crop all the image files in a folder. Can you please help me? I am new to PHP, and I cannot figure out how to do it properly.
<?php
$dir = "PATH TO DIRECTORY";
$exclude = array("jpg", "jpeg", "png", "gif");
if (is_dir($dir)) {
$files = scandir($dir);
foreach($files as $file){
if(!in_array($file,$exclude)){
// DO SOMETHING
}
}
}
?>
Image cropping function to be called inside the function above found below
function PIPHP_ImageCrop($image, $x, $y, $w, $h)
{
$tw = imagesx($image);
$th = imagesy($image);
if ($x > $tw || $y > $th || $w > $tw || $h > $th)
return FALSE;
$temp = imagecreatetruecolor($w, $h);
imagecopyresampled($temp, $image, 0, 0, $x, $y,
$w, $h, $w, $h);
return $temp;
}