0

If i am trying to create new image from existing .jpeg image will gives black(blank) image.

My Code:

$new_path = 'post/'.time().'-myimage.jpeg';
$src="post/myimage.jpeg";
$jpeg_quality = 90;
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor($my_post['w'], $my_post['h']);    
   imagecopyresampled($dst_r,$img_r,0,0,$my_post['x'],$my_post['y'],$my_post['w'],$my_post['h'],$my_post['w'],$my_post['h']);
    header('Content-Type: image/jpeg');
    imagejpeg($dst_r, $new_path, $jpeg_quality);
Rahul K
  • 413
  • 3
  • 11

1 Answers1

0

If you use a filename in imagejpeg the jpeg isn't outputed to stdout - it's saved to the given file name. You have to use null as file name.

imagejpeg($dst_r, null, $jpeg_quality);

if you want also to save the picture, you have to call the function twice or redirect the file contents to the server with some function like readfile.

Philipp
  • 15,377
  • 4
  • 35
  • 52