Setting an alpha channel when constructing an ImagickPixel

拈花ヽ惹草 提交于 2020-01-02 18:33:07

问题


I am new to using ImageMagick. I am using the latest imagick extension (3.1.0rc1) with PHP. However, the documentation for imagick seems to be somewhat sparse.

I want to create an ImagickPixel object with an alpha channel. The documentation states that these are some valid color values to pass to the constructor: "blue", "#0000ff", "rgb(0,0,255)", "cmyk(100,100,100,10)", etc.

I know that it is possible to retrive the alpha value of an ImagickPixel using getColorValue(imagick::COLOR_ALPHA);.

So, how can I set an rgb color with an alpha channel during initialization of the object by passing to the constructor?


回答1:


Looks like the way to do it is to just use rgba:

$myImagickPixel = new ImagickPixel("rgba(250,15,150,0)"); //Where the last digit is the alpha and 0 is transparent and 1 is fully opaque.



回答2:


I found some documentation on the allowed formats:

http://www.imagemagick.org/script/color.php

The format you want is "#rrggbbaa", so half-transparent red is "#FF00007F".



来源:https://stackoverflow.com/questions/10103763/setting-an-alpha-channel-when-constructing-an-imagickpixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!