我想使用 PHP GD 為一些 PNG 著色。出于測試目的,我對紅色 (255,0,0) 進行了硬編碼,稍后將替換為動態變量。例如我有這兩個圖像:圖 1: 圖 2: 使用我的代碼,只有圖像 2 可以正常工作。 然而,狗圖像有某種灰色框,不知道這是從哪里來的。 這是我正在使用的代碼:<?php$im = imagecreatefrompng('dog.png');imagealphablending($im, false);imagesavealpha($im, true);$w = imagesx($im);$h = imagesy($im);for ($x = 0; $x < $w; $x++) { for ($y = 0; $y < $h; $y++) { $color = imagecolorsforindex($im, imagecolorat($im, $x, $y)); $r = ($color['red'] * 255) / 255; $g = ($color['green'] * 0) / 255; $b = ($color['blue'] * 0) / 255; imagesetpixel($im, $x, $y, imagecolorallocatealpha($im, $r, $g, $b, $color['alpha'])); }}imagepng($im, 'result.png');imagedestroy($im);為什么它適用于圖像 2 而不適用于圖像 1?我只能想到圖像 1 上的某種 alpha 蒙版。希望有人可以幫助我
- 3 回答
- 0 關注
- 180 瀏覽
添加回答
舉報
0/150
提交
取消