I'm trying to crop then resize an image on PHP v5.4
, I've read these resources
- Put PNG over a JPG in PHP
- http://php.net/manual/en/function.imagecopy.php
- http://php.net/manual/en/function.imagecopyresampled.php
- http://php.net/manual/en/function.call-user-func-array.phPP
- PHP watermarking
- http://php.net/manual/en/function.imagecreatetruecolor.php
My code is based off the answer from Cropping image in PHP (the dimensions between these images vary alot).
I want to resize this image from 1151x768
to 200x82
and crop the background section at x: 0, y: 686
I'd prefer not bloating the question with the entire 600 lines in this question, $output
refers to setwidth1200nzpioneerthursday08398
image
<?php
$output = imagecreatefromjpeg("setwidth1200nzpioneerthursday08398.jpg");
$source_crop_image = imagecreatetruecolor(200, 82);
if(!is_resource($source_crop_image)) {
return $source_crop_image;
}
imagealphablending($output, true);
$source_copy_result = imagecopy($output, $source_crop_image, 0, 0, 0, 686, 200, 82);
$source_copy_result = (bool) $source_copy_result;
if(!$source_copy_result) {
return false;
}
$source_image_result = imagejpeg($source_crop_image, "images/mynewimage.jpg");
$source_image_result = (bool) $source_image_result;
?>
My Image setwidth1200nzpioneerthursday08398
Ideally I'm trying to get it crop the RED SECTION, while keeping the scale intact then resizing to 200x82
My Result
My Expected Result (I created this image using GIMP).
I have no idea why my resulting image is a black box ..