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系统下可以直接提取压缩文件,得到三个文 ...
随机推荐
- 利用最新版的RubyMine2016.2开发Ruby On Rails 程序
经过我的前两篇博文 ”Ruby On Rails环境搭建“ 和”Ruby On Rails 环境搭建MySQL数据库连接“ 我们已经具备了开发Ruby On Rails程序的一切要素,但是天天对着do ...
- C++多线程调试和测试的注意事项
在一个程序中,这些独立运行的程序片断叫作“线程”(Thread),利用它编程的概念就叫作“多线程处理”.利用线程,用户可按下一个按钮,然后程序会立即作出响应,而不是让用户等待程序完成了当前任务以后才开 ...
- HashMap和HashTable区别
HashMap和HashTable区别 HashMap--->允许控制/线程安全 HashTable-->线程不安全
- nginx的基本配置和虚拟主机的配置
在Nginx配置文件(nginx.conf)中,一个最简化的虚拟主机配置代码如下: 跟Apache -样,Nginx也可以配置多种类型的虚拟圭机:一是基于IP的虚拟主机,二是基于域名的虚拟主机,三是基 ...
- SparkSQL基础应用(1.3.1)
一.概述 从1.3版本开始Spark SQL不再是测试版本,之前使用的SchemaRDD重命名为DataFrame,统一了Java和ScalaAPI. SparkSQL是Spark框架中处理结构化数据 ...
- 浅谈JavaScript计时器
JavaScript计时器 1.什么是JavaScript计时器? 在JavaScript中,我们可以在设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行. 2.计时器类型 一次性计时器:仅在 ...
- PAT乙级 1018. 锤子剪刀布 (20)
1018. 锤子剪刀布 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大家应该都会玩“锤子剪刀布”的游 ...
- 本周PSP+历年作品评论
本周PSP 类别 内容 开始时间 结束时间 间断时间 净时间(min) 9月11号 看书 构建之法 19:00 21:00 14 106 9月12号 写程序 词频统计多需求版 8:00 14:23 3 ...
- 《OpenGL着色语言》理解点记录三
“帧缓冲区”中的“帧”的含义? “帧”是连续图像中的一幅,3D可视化程序最终都是转化为一幅幅的图像输出在显示器上,这一幅幅的图像叫做叫“帧”. 解释“glBlendFunc(GL_SRC_AL ...
- hadoop之输入输出格式
<STRONG>jobConf.setInputFormat(MyInputFormat. class ); InputFormat:</STRONG> TextInputFo ...