如何在缩略图中添加背景颜色或在php中更改颜色以尝试为缩略图添加背景?
private function _generateThumb() {
switch($this->imageType) {
case 'jpg':
$image = @imagecreatefromjpeg($this->pathToImage);
break;
case 'gif':
$image = @imagecreatefromgif($this->pathToImage);
break;
case 'png':
$image = @imagecreatefrompng($this->pathToImage);
break;
}
if ($image === false) {
trigger_error('image could not be created', 1024);
print 'nöööööö'; exit;
}
$thumbImage = @ImageCreateTrueColor(933, $this->thumbHeight);
//select background color using number between 0 to 255
$color = imagecolorallocate($thumbImage,0,0,0);//black color
imagefill($thumbImage, 0, 0, $color);
if ($this->imageType == 'png' || $this->imageType == 'gif')
{
imagealphablending($thumbImage, false);
$s=933-$this->thumbWidth;
$s=$s/2;//to keep image in center i.e distance from x-axis
ImageCopyResampled($thumbImage, $image,$s,0,0,0, $this->thumbWidth,
$this->thumbHeight,$this->imageWidth, $this->imageHeight);
答案 0 :(得分:0)
//select background color using number between 0 to 255
$color = imagecolorallocate($thumbImage,0,0,0);//black color
//$color=imagecolorallocate($thumbImage,255,255,255) white color
imagefill($thumbImage, 0, 0, $color);
//use range 0 to 255 to add colors to thumbnail background