Jump to content

Help with cropping images using GD lib


peuge

Recommended Posts

Hey all,

 

So I have a picture and when I click on it a crop box appear and I select the area I want to crop from the picture.

Once this is done I click the crop button and that sends the co-ordinates of my selection via JSON to a php file found below.

I have checked that all the values that are being sent are correct. My problem is that when I crop it does not crop it instead zooms into the picture. I am new to GD but could anyone please help. Thanks. I have also tried all the other imagecopy commands and they dont work.

 

    
   header('Content-Type: image/png');
    $coords = json_decode(stripslashes($_GET['coOrds']));

$filename = "beach.png";

        //The values below are from the crop box used on the original picture ($filename)
$x1 = $coords[0];//top left hand corner 
$y1 = $coords[1];//top right hand corner
$x2 = $coords[2];// bottom right corner
$y2 = $coords[3];//bottom right corner
$width = $coords[4];
$height = $coords[5];

$canvSize = getimagesize($filename); //size of original picture	
$source = imagecreatefrompng($filename);
$newImg = imagecreatetruecolor($width,$height);	

imagecopyresampled($newImg, $source, 0,0, $x1, $y1, $width, $height, $width, $height);
imagepng($newImg);

Link to comment
https://forums.phpfreaks.com/topic/148604-help-with-cropping-images-using-gd-lib/
Share on other sites

None of the imagecopy* functions work. I did not try imagecopymerge before, but it also does not work. Does anyone know why this might be? What basically happens is it just zooms in on the portion of picture I have selected and puts it into the destImg? All I want to do is take a part of an image and put it into another image.

 

Any help appreciated.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.