Home > Backend Development > PHP Tutorial > gd - php图片旋转问题

gd - php图片旋转问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:41:35
Original
1943 people have browsed it

<code>$fullFileName = $uploadImgDir."/".$filename;
    $thumbFileName = $filename.".thumb";
    if ($type =  pathinfo($fullFileName, PATHINFO_EXTENSION)) {
        switch ($type) {
            case 'jpg';
            $isJpeg = true;
            break;
            case 'gif';
            $isGif = true;
            break;
            case 'png';
            $isPng = true;
            break;
            default:
                return false;
        }
        // Load
        if(isset($isGif) && $isGif){
            $source = imagecreatefromgif($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagegif($rotate,$fullFileName,100);
            return true;
        }elseif(isset($isJpeg) && $isJpeg){
            $source = imagecreatefromjpeg($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagejpeg($rotate,$fullFileName,100);
            return true;
        }elseif(isset($isPng) && $isPng){
            //这个地方报错了
            **$source = imagecreatefrompng($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagepng($rotate,$fullFileName,100);**
            return true;
        }else{
            return false;
        }
</code>
Copy after login
Copy after login

jgp的旋转没问题,png 报错了
imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
求解决
或者求png图片旋转的好方法

回复内容:

<code>$fullFileName = $uploadImgDir."/".$filename;
    $thumbFileName = $filename.".thumb";
    if ($type =  pathinfo($fullFileName, PATHINFO_EXTENSION)) {
        switch ($type) {
            case 'jpg';
            $isJpeg = true;
            break;
            case 'gif';
            $isGif = true;
            break;
            case 'png';
            $isPng = true;
            break;
            default:
                return false;
        }
        // Load
        if(isset($isGif) && $isGif){
            $source = imagecreatefromgif($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagegif($rotate,$fullFileName,100);
            return true;
        }elseif(isset($isJpeg) && $isJpeg){
            $source = imagecreatefromjpeg($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagejpeg($rotate,$fullFileName,100);
            return true;
        }elseif(isset($isPng) && $isPng){
            //这个地方报错了
            **$source = imagecreatefrompng($fullFileName);
            $rotate = imagerotate($source, $degrees, 0);
            imagepng($rotate,$fullFileName,100);**
            return true;
        }else{
            return false;
        }
</code>
Copy after login
Copy after login

jgp的旋转没问题,png 报错了
imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data
求解决
或者求png图片旋转的好方法

imagepng($rotate,$fullFileName,100);的问题
把第三个参数去掉就行了。不知道具体原因。
第三个参数是保真度,png为什么不能100%保真。

可以参考 OSC链接

路由规则可以根据自己需求重写~~~~~~~~~~

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template