如何使用PHP使用Imagick着色图像?

我想知道如何像使用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有办法解决这个问题吗?

感谢您的帮助!

cupid_llh 回答:如何使用PHP使用Imagick着色图像?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2674386.html

大家都在问