0

アルファ透過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 サイトのヘルプはあまり包括的ではなく、文書化されていない機能がたくさんあります。

ありがとう。

4

1 に答える 1

1

コマンドラインでは、次のようにします。

convert test.png -transparent-color white PNG8:converted.png

しかし、一部の IM バージョンでは、このタイプの変換に問題があるようです。同様の問題を抱えていると思われる人物によるこのユーザーグループの投稿を見つけました: http://studio.imagemagick.org/pipermail/magick-users/2009- 5月/022534.html

IM を操作するときにコマンド ラインを使用していますか、それとも PHP モジュール ( http://de.php.net/manual/en/book.imagick.php ) を使用していますか?

于 2010-06-15T07:40:02.353 に答える