当我从它创建缩略图时,我在尝试保持png的透明度方面遇到一些麻烦,任何人都有这方面的经验吗?任何帮助都会很棒,这就是我目前正在做的事情:
$fileName= "../js/ajaxupload/tees/".$fileName; list($width, $height) = getimagesize($fileName); $newwidth = 257; $newheight = 197; $thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagesavealpha($thumb, true); imagepng($thumb,$newFilename);
Tom Haigh.. 85
我过去曾成功地这样做过:
$thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, false); imagesavealpha($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagepng($thumb,$newFilename);
我发现输出的图像质量要好得多使用imagecopyresampled()
比imagecopyresized()
我过去曾成功地这样做过:
$thumb = imagecreatetruecolor($newwidth, $newheight); imagealphablending($thumb, false); imagesavealpha($thumb, true); $source = imagecreatefrompng($fileName); imagealphablending($source, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagepng($thumb,$newFilename);
我发现输出的图像质量要好得多使用imagecopyresampled()
比imagecopyresized()
忘记颜色透明度索引,它永远不会适用于所有渲染产品.而是使用alpha图层蒙版:
$image = imagecreatetruecolor($size, $size); imagealphablending($image, false); imagesavealpha($image, true); $trans_layer_overlay = imagecolorallocatealpha($image, 220, 220, 220, 127); imagefill($image, 0, 0, $trans_layer_overlay);