duandaijian1583 2014-06-18 15:23
浏览 342
已采纳

PHP Imagick颜色灰度渐变

I'am new to Imagick and PHP. The thing I want to make is to put a RGB color on gray-scale gradient.

Input:

Input

Output:

enter image description here

The output color may be different. Any idea would be helpful.

Thanks in advance! Greetigns,

  • 写回答

1条回答 默认 最新

  • dougan1884 2014-06-18 20:32
    关注

    There is the colorizeImage function which would do what you asked.

    function colorizeImage($imagePath, $color, $opacity) {
        $imagick = new \Imagick(realpath($imagePath));
        //TBH - not sure if opacity is meant to be on the color or colorize call
        //neither seem to have much effect.
        $opacity = $opacity / 255.0;
        $opacityColor = new \ImagickPixel("rgba(0, 0, 0, $opacity)");
        $imagick->colorizeImage($color, $opacityColor);
        header("Content-Type: image/jpg");
        echo $imagick->getImageBlob();
    }
    
    
    $color = "rgb(252, 38, 231)";
    $opacity = 0.5
    colorizeImage("someImage.png", $color, opacity);
    

    However, why do you want to do it like that? You can just create a colorized gradient directly.

    $opacity = new \Imagick();
    $opacity->newPseudoImage(100, 50, "gradient:rgb(255,128,128,0.5)-none");
    
    //Gradients are created down
    $opacity->rotateimage('black', 90);
    

    Which creates a perfect gradient in one step.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题