我已经为用户提供了一个将图片导出为JPG的选项,并且我还存储了png图像
为此,我创建了一些php脚本。
巴布亚新几内亚正在转换罚款..。
但是当我下载jpg图像并尝试在图像查看器中打开时,它的显示就损坏了。
我的php代码:
将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");
}我做错什么了?
或
有什么更好的办法吗?
提前谢谢
发布于 2013-05-15 12:45:21
https://stackoverflow.com/questions/16565201
复制相似问题