Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert png to jpg and download jpg image
    text
    copied!<p>I have given an option to user to Export Images As JPG and I have stored png images<br/> So, i have created some php script to do so.<br> png is converting fine..<br> but when i downloaded the jpg image and try to open in image viewer, its showing corrupted. <br>My php code:</p> <p><strong>Converting PNG to JPG</strong></p> <pre><code>$input_file = 'images/image1364926178.png'; $filename = time().'.jpg'; $output_file = 'images/'.$filename; $input = imagecreatefrompng($input_file); if($input){ list($width, $height) = getimagesize($input_file); $output = imagecreatetruecolor($width, $height); $white = imagecolorallocate($output, 255, 255, 255); imagefilledrectangle($output, 0, 0, $width, $height, $white); imagecopy($output, $input, 0, 0, 0, 0, $width, $height); imagejpeg($output,$output_file); } </code></pre> <p><strong>Script downloading jpg image</strong> <br></p> <pre><code>$Image_file_name = '/images/'.$filename; $filedetail = getimagesize($filename); $mimetype = $filedetail['mime']; if (file_exists($filename)) { @ob_end_clean(); header('Content-Description: File Transfer'); header('Content-Type: '.$mimetype); header('Content-Disposition: attachment; filename='.basename($filename)); header("Content-Transfer-Encoding: binary"); header('Accept-Ranges: bytes'); header('Cache-Control: private'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); } </code></pre> <p>What am i doing wrong? <br>OR<br>Is there any better idea for how to do that?</p> <p>Thanks in Advance </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload