首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将png转换为jpg并下载jpg映像。

将png转换为jpg并下载jpg映像。
EN

Stack Overflow用户
提问于 2013-05-15 12:38:06
回答 1查看 2.7K关注 0票数 0

我已经为用户提供了一个将图片导出为JPG的选项,并且我还存储了png图像

为此,我创建了一些php脚本。

巴布亚新几内亚正在转换罚款..。

但是当我下载jpg图像并尝试在图像查看器中打开时,它的显示就损坏了。

我的php代码:

将PNG转换为JPG

代码语言:javascript
复制
$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图像

代码语言:javascript
复制
$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");
}

我做错什么了?

有什么更好的办法吗?

提前谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-15 12:45:21

一个简单的谷歌让我得到这个question on stackoverflow,一个简单的函数被赋予转换图像。

为了获得正确的jpg标题,我找到了this answer

把两者结合起来就能做好这件事

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16565201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档