Yeniden boyutlandırma Grayscale PNG beyaz çizgiler göründüğünde

0 Cevap php

Bazı png görüntüleri yeniden boyutlandırma zaman gergin görünür ve dikey birleşmelerin ne gibi görünüyor. Ancak ben görüntü tonlamalı başlar ve farklı bir renk profili olması gerekiyor onun için düşünmeye başlıyorum, sorun nerede olabilir emin değilim.

Herhangi bir yardım veya öneri büyük mutluluk duyacağız.

function createImageSize($sourcefile, $setNewName, $maxwidth, $maxheight, $quality){

    $fileInfoArray = @getimagesize($sourcefile);
    $imagetype = $fileInfoArray['mime'];

    list($width, $height, $attr) = getimagesize($sourcefile);

    switch($imagetype){
        case 'image/jpeg':
            $img = imagecreatefromjpeg($sourcefile);
            break;

        case 'image/gif':
            $img = imagecreatefromgif($sourcefile);
            break;

        case 'image/png':
            $img = imagecreatefrompng($sourcefile);
            break;

        case 'image/x-png':
            $img = imagecreatefrompng($sourcefile);
            break;
    }

    if ($width > $maxwidth || $height > $maxheight){   
        if ( $width > $height ){
            $newwidth = $maxwidth;
            $ratio = $maxwidth / $width;
            $newheight = floor($height * $ratio);

            if ($newheight > $maxheight){
                $newheight = $maxheight;
                $ratio = $maxheight / $height;
                $newwidth = floor($width * $ratio);
            }
        }else{
            $newheight = $maxheight;
            $ratio = $maxheight / $height;
            $newwidth = floor($width * $ratio);

            if ($newwidth > $maxwidth){
                $newwidth = $maxwidth;
                $ratio = $maxwidth / $width;
                $newheight = floor($height * $ratio);
            }
        }
    }else{
        $newwidth = $width;
        $newheight = $height;
    }   

    $tmpimg = imagecreatetruecolor( $newwidth, $newheight );

    if($imagetype == 'image/png'||$imagetype == 'image/x-png'){
        imagealphablending($tmpimg, false);
        imagesavealpha($tmpimg, true);

        if($imagetype == 'image/gif'){
            $transparent = imagecolorallocatealpha($tmpimg, 0, 0, 0, 127);
            imagecolortransparent($tmpimg, $transparent);
        }

        imagefilledrectangle($tmpimg, 0, 0, $newwidth, $newheight, $transparent);
    }

    imagecopyresampled( $tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );

    switch($imagetype){
        case 'image/jpeg':
            imagejpeg($tmpimg, $setNewName, $quality);
            break;

        case 'image/gif':
            imagegif($tmpimg, $setNewName);
            break;

        case 'image/png':
            imagepng($tmpimg, $setNewName, 3);
            break;

        case 'image/x-png':
            imagepng($tmpimg, $setNewName, 3);
            break;
    }
    imagedestroy($tmpimg);
    imagedestroy($img);
}

0 Cevap