0

I have the following code which displays a cropped image on the screen, but I would like this image to automatically download as well as display on screen.

The file name can be anything random.

$targ_w = 800;
$targ_h = 600;

$jpeg_quality = 80;

$vImg = @imagecreatefromjpeg($_FILES['image_file']['tmp_name']);

$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$vImg,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);

header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
Tom
  • 12,776
  • 48
  • 145
  • 240
  • Change the second parameter in imagejpeg() to specify a filename. Also a simple Stackoverflow search can find your solution. http://stackoverflow.com/questions/40943/how-to-automatically-start-a-download-in-php – Nick Tucci Aug 12 '14 at 16:22
  • don't use the `@` suppression operator. it's the coding equivalent of stuffing your fingers in your ears and going "lalalalalala can't hear you". – Marc B Aug 12 '14 at 16:35

0 Answers0