Rumah >pembangunan bahagian belakang >tutorial php >gd - php图片旋转问题

gd - php图片旋转问题

WBOY
WBOYasal
2016-06-06 20:41:351858semak imbas

<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>

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>

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

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

可以参考 OSC链接

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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn