gd-jpeg: JPEG library reports unrecoverable error 解决办法
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\AppServ\www\mercPhoto.php on line 90
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'comp_logo/200803171023127332.jpg' is not a valid JPEG file in
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\AppServ\www\mercPhoto.php on line 100
解决见代码。
/**
* 等比例压缩图片
* @param String $src_imagename 源文件名 比如 “source.jpg”
* @param int $maxwidth 压缩后最大宽度
* @param int $maxheight 压缩后最大高度
* @param String $savename 保存的文件名 “d:save”
* @param String $filetype 保存文件的格式 比如 ”.jpg“
* @version 1.0
*/
function resizeImage($src_imagename,$maxwidth,$maxheight,$savename,$filetype)
{ $typeArr=explode(".",$filetype);
$type=$typeArr[];
switch($type)
{
case "png":
$im=imagecreatefrompng($src_imagename);
break; case "jpeg":
$im=imagecreatefromjpeg($src_imagename);
break; case "gif":
$im=imagecreatefromgif($src_imagename);
break;
} $current_width = imagesx($im);
$current_height = imagesy($im); if(($maxwidth && $current_width > $maxwidth) || ($maxheight && $current_height > $maxheight))
{
if($maxwidth && $current_width>$maxwidth)
{
$widthratio = $maxwidth/$current_width;
$resizewidth_tag = true;
} if($maxheight && $current_height>$maxheight)
{
$heightratio = $maxheight/$current_height;
$resizeheight_tag = true;
} if($resizewidth_tag && $resizeheight_tag)
{
if($widthratio<$heightratio)
$ratio = $widthratio;
else
$ratio = $heightratio;
} if($resizewidth_tag && !$resizeheight_tag) $ratio = $widthratio;
if($resizeheight_tag && !$resizewidth_tag)
$ratio = $heightratio; $newwidth = $current_width * $ratio;
$newheight = $current_height * $ratio; if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($newim,$im,,,,,$newwidth,$newheight,$current_width,$current_height);
}
else
{
$newim = imagecreate($newwidth,$newheight);
imagecopyresized($newim,$im,,,,,$newwidth,$newheight,$current_width,$current_height);
} $savename = $savename.$filetype;
imagejpeg($newim,$savename);
imagedestroy($newim);
}
else
{
$savename = $savename.$filetype;
imagejpeg($im,$savename);
}
die; }
gd-jpeg: JPEG library reports unrecoverable error 解决办法的更多相关文章
- imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable
错误: imagecreatefromstring(): Empty string or invalid image 或者 imagesx() expects parameter 1 to be re ...
- Eclipse中引入com.sun.image.codec.jpeg包报错的完美解决办法
转: Eclipse中引入com.sun.image.codec.jpeg包报错的完美解决办法 更新时间:2018年02月14日 17:13:03 投稿:wdc 我要评论 Java开发中 ...
- com.sun.image.codec.jpeg在Eclipse中报错的解决办法
在Eclipse中处理图片,需要引入两个包:import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEG ...
- VMware unrecoverable error解决方法
把开发环境部署在虚拟机里面,重装系统后不须要再反复部署开发环境. 可是有时候异常退出虚拟机会导致错误.之前出现打开虚拟机之后,系统分辨率错误,就是点击的位置和显示的位置不一样. 于是又一次关了虚拟机, ...
- CentOS5/6/7系统下搭建安装Amabari大数据集群时出现SSLError: Failed to connect. Please check openssl library versions.错误的解决办法(图文详解)
不多说,直接上干货! ========================== Creating target directory... ========================== Comman ...
- 全网最详细的启动zkfc进程时,出现INFO zookeeper.ClientCnxn: Opening socket connection to server***/192.168.80.151:2181. Will not attempt to authenticate using SASL (unknown error)解决办法(图文详解)
不多说,直接上干货! at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:) at org ...
- php编译中遇到种种error解决办法
http://my.oschina.net/maczhao/blog/365176 编译PHP5.5 make 时出现错误 make: *** [ext/fileinfo/libmagic/appre ...
- 启动Eclipse弹出:Failed to load JavaHL Library 错误框的解决办法
一.问题背景描述: eclipse安装完svn插件以后,在启动时出现:Failed to load JavaHL Library. These are the errors that were en ...
- Ubuntu 16.04 LTS 下安装MATLAB2015b 以及Matlab system error解决办法
下载MATLAB2015b破解版 操作系统:Ubuntu 16.o4 LTS 程序文件:Matlab2015b-glnxa64破解版 解压提取文件:在ubuntu系统下可以直接提取压缩文件,得到三个文 ...
随机推荐
- [转]SecureCRT使用配置详细图文教程
Secure CRT是一款支持 SSH2.SSH1.Telnet.Telnet/SSH.Relogin.Serial.TAPI.RAW 等协议的终端仿真程序,最吸引我的是,SecureCRT ...
- HashMap和HashTable区别
HashMap和HashTable区别 HashMap--->允许控制/线程安全 HashTable-->线程不安全
- java数组获取最值
import java.util.Random; /** * 获取最大值最小值 * @author shaobn * */ public class Test2 { public static voi ...
- cometd使用-bayeux协议(读法:贝叶)
bayeux.createChannelIfAbsent("/**", new ServerChannel.Initializer() { @Override public voi ...
- yii2的redis扩展使用
yii2支持了redis扩展,不需要在本地下载php的扩展库就可以很好的使用 1.下载windows的redis安装包打开cmd,进入安装包目录,使用redis-server.exe redis.co ...
- 累加两个php数组,键相同的累加,不同的合并
1. $arr1=array('name'=>33,'type'=>1); $arr2=array('name'=>33,'price'=>200); $res=array() ...
- 《OpenGL游戏编程》第9章-PlanarShadow关键代码注释
阴影这块确实是难点.说到阴影就必须提到投影矩阵.模板值为1和2时分别渲染.说来话长,仅仅放上代码,供日后查阅. /** 渲染墙面和阴影 */ void CPlanarShadow::Render() ...
- android 应用架构随笔二(定义BaseApplication并配置Application)
定义BaseApplication并配置Application import android.app.Application; import android.os.Handler; /** * * = ...
- JVM总结
1. 内存分布: 1). 程序计数器(Program Counter Register)是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器.线程私有.如果线程正在执行的是一个J ...
- Error while trying to retrieve text for error ORA-01019 的解决办法
这个问题涉及到 64 位的oracle服务, 和32位的客户端导致的问题. 环境如下: win8.1 + 64位oracle 11.1 做服务器, 客户端由于采用32位程序,不支持64位的oracle ...