Home >Backend Development >PHP Tutorial >图片压缩的有关问题

图片压缩的有关问题

WBOY
WBOYOriginal
2016-06-13 12:15:241032browse

图片压缩的问题
imagecreatefromjpeg操作jpg图片压缩时候警告,图片为0字节。本地是可以的。服务器上不行。看了PHP的GD也有打开,不知道是什么原因了?


------解决思路----------------------
你的服务器在编译 gd 是没有打开 --jpeg 开关

------解决思路----------------------
gd有問題,重裝一個看看。
------解决思路----------------------
先判断一下图片类型,再用调用对应的方法打开。

<br />$obj = new finfo(FILEINFO_MIME_TYPE);<br />$type = $obj->file($file);<br /><br />switch($type){<br />    case 'image/gif': $img = imagecreatefromgif($file); break;<br />    case 'image/jpeg': $img = imagecreatefromjpeg($file); break;<br />    case 'image/png': $img = imagecreatefrompng($file); break;<br />    default: return false;<br />}<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn