我想知道如何像使用GD一样使用Imagick为图像着色。 因此,我正在寻找与之等效的Imagick:
class MyIMG {
public function __construct($pathToIMG=''){
$this->img = imagecreatefrompng($pathToIMG);
}
public function colorize($color=''){
// if $color input is HEX turn it into RGB array
if( !is_array($color) ){
list($r,$g,$b) = sscanf($color,"#%02x%02x%02x");
$color = [$r,$b];
}
$rgb = $color ?: [0,0];
$rgb = [ 255-$rgb[0],255-$rgb[1],255-$rgb[2] ];
imagefilter($this->img,IMG_FILTER_NEGATE);
imagefilter($this->img,IMG_FILTER_COLORIZE,$rgb[0],$rgb[1],$rgb[2]);
imagefilter($this->img,IMG_FILTER_NEGATE);
imagealphablending( $this->img,false );
imagesavealpha( $this->img,true );
imagepng( $this->img );
}
public function img(){
return $this->img;
}
}
我这样使用它:
header('Content-Type: image/png');
$img = new MyLib('path/to/image.png');
$img->colorize('#FF0000');
$img->img();
Imagick有办法解决这个问题吗?
感谢您的帮助!