2012-07-26 42 views
0

我有这个功能,当我传递一个比我想创建的裁剪更小的图像时,它会制作更大尺寸的图像,那就没事了,但其余的图像没有图像,它用黑色填充,你知道如何用fe来强制它产生白色或特定的颜色数组(255,255,255)??功能裁剪图像创建背景颜色

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

bed

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; 
} 

回答

0

使用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; 
}