アルファ透過png画像をパレットベースのpng画像に変換したい。
GD では、簡単に実行できます。
// We have already the image loaded in $source_img
$w=200; $h=200; // We supose that img dimensions are 200x200
$img = imagecreatetruecolor($w, $h); // New black image
list($r, $g, $b) = array(200, 200, 200); // Some color that doesn't appear in image to avoid conflict
$color = imagecolorallocate($img, $r, $g, $b);
imagefill($img, 0, 0, $color); // Fill the black image with the chosen color.
imagecolortransparent($img, $color); // Set the chosen color as transparent
$res = imagecopyresampled($img, $source_img, 0, 0, 0, 0, $w, $h, $w, $h);
しかし、Imagick では、色を透明に設定する方法がわかりません (GD の imagecolortransparent())。インターネットで何時間も検索しましたが、php サイトのヘルプはあまり包括的ではなく、文書化されていない機能がたくさんあります。
ありがとう。