【问题标题】:function to crop image create background color裁剪图像创建背景颜色的功能
【发布时间】:2012-07-27 04:56:42
【问题描述】:

我有这个功能,当我传递一个小于我想要创建的裁剪的图像时,它会生成更大尺寸的图像,没关系,但其余没有图像的地方,它用黑色填充,你知道如何通过使用 f.e. 来强制它创建白色或特定颜色吗?数组(255,255,255)??

这是它为你创建的图片,让你直接看到我的意思。

public function crop($x, $y, $width, $height)
{
    $copy=imagecreatetruecolor($width,$height);
    //$this->img = imagecolorallocate($this->img, 23, 123, 456);
    if (imagecopy($copy, $this->img, 0, 0, $x, $y, $width, $height)) {
        $this->img=$copy;
        return true;
    }

    return false;
}

【问题讨论】:

    标签: php


    【解决方案1】:

    创建图片后使用imagefill设置图片颜色。

    public function crop($x, $y, $width, $height)
    {
        $copy=imagecreatetruecolor($width,$height);
        imagefill($copy, 0, 0, imagecolorallocate($copy, 255, 255, 255));// fill with white
        //$this->img = imagecolorallocate($this->img, 23, 123, 456);
        if (imagecopy($copy, $this->img, 0, 0, $x, $y, $width, $height)) {
            $this->img=$copy;
            return true;
        }
    
        return false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      相关资源
      最近更新 更多