将png转换为jpg并下载jpg图像
问题描述:
我给出了一个选项让用户将图像导出为JPG,并且存储了png图像
所以,我创建了一些php脚本来这样做。
PNG转换罚款..
但当我下载JPG图像,并尝试在图像查看器中打开,其显示损坏。
我的PHP代码:将png转换为jpg并下载jpg图像
转换PNG至JPG
$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);
}
脚本下载的JPG图片
$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");
}
我到底做错了什么?
或
有没有更好的主意,如何做到这一点?
由于提前