crop image top-middle

See all posts Reply

crop image top-middle new!
by vio, 16 years, 9 months ago
I would like to crop image from top and middle but i dont know how...Reply
Re: crop image top-middle new!
by colin, 16 years, 9 months ago
Can you explain a little bit more what you want to do?

What is your code, can you paste it here?Reply
Re: crop image top-middle new!
by Test, 16 years, 8 months ago
// Set our crop dimensions.
$width = 100;
$height = 75;
// Get dimensions of existing image
$dimensions = getimagesize('path/to/image');
// Prepare canvas
$canvas = imagecreatetruecolor($width,$height);
$piece = imagecreatefromjpeg('path/to/image');
// Prepare image resizing and crop -- Center crop location
$newwidth = $dimensions[0] / 2;
$newheight = $dimensions[1] / 2;
$cropLeft = ($newwidth/2) - ($width/2);
$cropHeight = ($newheight/2) - ($height/2);
// Generate the cropped image
imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $width, $height, $newwidth, $newheight);
// Write image or fail
if (imagejpeg($canvas,'path/to/save/file',90)) {
echo 'Image crop successful';
} else {
echo 'Image crop failed';
// Clean-up
Re: crop image top-middle new!
by Yaser Riaz, 2 years, 2 months ago
Hi, by using your code, the image is being saved but it is all black, can you tell me what the issue could beReply