1
當我嘗試轉換png - > PNG與調整大小我得到的透明度呈現爲具體的顏色:#ff00ff;PHP png:透明度轉換爲可見顏色。如何避免它?
下面是結果:
http://i.stack.imgur.com/1xTd5.png
下面是代碼:
<?php
$image = __DIR__ . '/image/data/10891.png'; // local file
$image = 'http://content.wuala.com/contents/mike.walker/sharing/10891.png?dl=1'; // source file in public
$scale = 1;
// Get meta for image
$info = getimagesize($image);
$info = array(
'width' => $info[ 0 ],
'height' => $info[ 1 ],
'bits' => $info[ 'bits' ],
'mime' => $info[ 'mime' ]
);
// Get res for image
$image = imagecreatefrompng($image);
$width = $info['width'] * $scale;
$height = $info['height'] * $scale;
$new_width = (int)($info[ 'width' ] * $scale);
$new_height = (int)($info[ 'height' ] * $scale);
$xpos = (int)(($width - $new_width)/2);
$ypos = (int)(($height - $new_height)/2);
$image_old = $image;
$image = imagecreatetruecolor($width, $height);
//imagetruecolortopalette($image, FALSE, 255);
imagealphablending($image, false);
imagesavealpha($image, true);
$background = imagecolorallocatealpha($image, 255, 255, 255, 128);
imagecolortransparent($image, $background);
imagefilledrectangle($image, 0, 0, $width, $height, $background);
imagecopyresampled($image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $info[ 'width' ], $info[ 'height' ]);
header('Content-type: image/png');
imagepng($image);
如何解決這個probled? 很高興爲您提供幫助。謝謝。
P.S.對不起我的英語不好。
如果我沒記錯的話,imagecopymerge工作不正常,*有時*圖像的合併是嘈雜的 – nulll 2012-09-07 12:33:23