[php,gd] png resize 투명처리하기. 프로그래밍

이미지 리사이징 할 일이 생겼다.

그런데 실제로 리사이징 해보니 아주 잘되었다.

근데...

png 리사이징 하니까 투명처리된 부분이 검게 변해버림... 아놔...

그래서 찾다가 스택오버플로우 발견해서 

png 투명처리 완료!

gd쪽은 나도 많이 해보지 않은 작업이라 일단 

코드만!


function resizePng($im, $dst_width, $dst_height) {
    $width = imagesx($im);
    $height = imagesy($im);

    $newImg = imagecreatetruecolor($dst_width, $dst_height);

    imagealphablending($newImg, false);
    imagesavealpha($newImg, true);
    $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
    imagefilledrectangle($newImg, 0, 0, $width, $height, $transparent);
    imagecopyresampled($newImg, $im, 0, 0, 0, 0, $dst_width, $dst_height, $width, $height);

    return $newImg;
}

출처 : http://stackoverflow.com/questions/279236/how-do-i-resize-pngs-with-transparency-in-php#279310

Tag :

Leave Comments