Save image after copying it with PHP's GD Library

404 views Asked by At

I'm cropping an image that was submitted through a form with a jQuery crop plugin. I have the following. But, how can I find out the path to the destination image?

$pic = $this->input->post('pic');

//Get the coordinates from the image crop
$x = $this->input->post('x');
$y = $this->input->post('y');
$w = $this->input->post('w');
$h = $this->input->post('h');

$src = imagecreatefromjpeg($pic);
$dest = ImageCreateTrueColor($w, $h);

imagecopy($dest, $src, $x, $y, $x, $y, $w, $h);
1

There are 1 answers

2
xatzistnr On BEST ANSWER

You just need to declare the path.

imagejpeg($dest, '/path/to/save.jpg', 90);

or for smaller images

imagepng($dest, '/path/to/save.jpg', 9);