zoukankan      html  css  js  c++  java
  • gd-jpeg: JPEG library reports unrecoverable error 解决办法

    Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:AppServwwwmercPhoto.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:AppServwwwmercPhoto.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[1];
                 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,0,0,0,0,$newwidth,$newheight,$current_width,$current_height);
                     }
                     else
                     {
                         $newim = imagecreate($newwidth,$newheight);
                        imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$current_width,$current_height);
                     }
              
                     $savename = $savename.$filetype;
                     imagejpeg($newim,$savename);
                     imagedestroy($newim);
                 }
                 else
                 {
                     $savename = $savename.$filetype;
                     imagejpeg($im,$savename);
                 }  
    die;
                       
            }
  • 相关阅读:
    关于自发电的一些想法
    折腾了一个晚上的业余时间,终于把一块廉价的tftlcd连到了我的树莓派上
    关于飞行器从外太空返回地球时候的减速器的思考与假象
    echart漏斗图背景多出一个方框的问题解决,浪费了两个小时的教训
    linux加密文件系统 fsck 无法修复一例
    天津
    [转]Bitmap图片缩放
    python spark 配置
    screen
    tar 命令
  • 原文地址:https://www.cnblogs.com/jthb/p/4095762.html
Copyright © 2011-2022 走看看