1

I'm trying to crop then resize an image on PHP v5.4, I've read these resources

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

Sample Image

Ideally I'm trying to get it crop the RED SECTION, while keeping the scale intact then resizing to 200x82

Crop Section

My Result

Result Image

My Expected Result (I created this image using GIMP).

Expected Result

I have no idea why my resulting image is a black box ..

classicjonesynz
  • 4,012
  • 5
  • 38
  • 78

1 Answers1

1

You have imagecopy() arguments in wrong order.

The right one is $source_copy_result = imagecopy($source_crop_image, $output, 0, 0, 0, 686, 200, 82);

smbdevin
  • 172
  • 1
  • 5