Hello I am trying to manipulate a bunch of images. What I am basically trying to do to each file (already got the list of filenames) is:
-Copy image into memory
-Get height and width of original
-Create new image resource with the same dimensions as original BUT 20 pixels off the height.
-Copy from the original image to the new image, cutting off 10 pixels from the top, 10 pixels from the bottom.
-Overwrite original.
This is the code I have:
foreach ($file_array as $file) {
$old_resource = imagecreatefromjpeg("funny_pictures/funny_pictures/$file");
// Get height and width of original image.
$old_height = imagesy($old_resource);
$old_width = imagesx($old_resource);
//Create new image which is 20 pixels smaller in height than original (10 from top, 10 from bottom)
$new_resource = imagecreatetruecolor($old_width, $old_height - 20);
//Copy from old image to new, leaving 10 pixels from top and 10 from bottom so height matches $new_resource
imagecopyresampled($new_resource, $old_resource, 0, 0, 0, 10, $old_width, $old_height - 20, $old_width, $old_height - 10);
//unlink the original.
unlink("funny_pictures/funny_pictures/$file");
//save new_resource to hard disk
imagejpeg($new_resource, "funny_pictures/funny_pictures/$file");
//echo out what picture was just done.
//destroy
imagedestroy($old_resource);
imagedestroy($new_resource);
echo $file."<BR>";
}
However it is not removing any space at all from the bottom of the image, and removing 10 or 20 pixels (cant tell?) from the top of the image.
Could somone please tell me what I am doing wrong.