You had few errors in your code. The imagejpeg output is logical, so your renaming always fails. You also never saved the modified image. You must use the 2nd parameter of imagejpeg and provide the correct file name for the new image. Also, make sure the new directory exists, otherwise the renaming will fail.
Fixed Code:
$in_filename = '4csrWqu9ngv.jpg'; list($width, $height) = getimagesize($in_filename); $offset_x = 0; $offset_y = 0; $new_height = $height - 65; $new_width = $width; $image = imagecreatefromjpeg($in_filename); $new_image = imagecreatetruecolor($new_width, $new_height); imagecopy($new_image, $image, 0, 0, $offset_x, $offset_y, $width, $height); /* Uncomment in case you want it also outputted header('Content-Type: image/jpeg'); imagejpeg($new_image); */ imagejpeg($new_image, $in_filename); rename($in_filename, 'new/' . $in_filename);
source share