How can I cut an image from the bottom using PHP?

gd, image, php

Solution

Here you go.

To change the name of the image, change $in_filename (currently 'source.jpg'). You can use URLs in there as well, although obviously that will perform worse.

Change the $new_height variable to set how much of the bottom you want cropped.

Play around with $offset_x, $offset_y, $new_width and $new_height, and you'll figure it out.

Please let me know that it works. :)

Hope it helps!

<?php

$in_filename = 'source.jpg';

list($width, $height) = getimagesize($in_filename);

$offset_x = 0;
$offset_y = 0;

$new_height = $height - 15;
$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);

header('Content-Type: image/jpeg');
imagejpeg($new_image);

?>

Problem

I want to take out the text in the bottom of an image. How can I cut it from bottom ...say 10 pixels to cut from bottom. I want do this in PHP. I have lots of images that have text in the bottom. Is there a way to do it?

Original source