小编Sco*_*ott的帖子

php imagecopyresampled添加黑色背景

我有一个调整大小的图像脚本,它采用130x81图像并将其添加到130x130图像,当imagecopyresampled函数运行时,它会在剩余的空间中添加黑色背景,即使基本图像是白色的.下面的代码,我真的很感激一些帮助.

我试图合并到创建的130x130文件的图像是: 130x81图像

$width = 130;
$height = 130;
$filename = 'process-add.jpg'; //130x81px jpg
$this->_image = imagecreatefromjpeg($filename);

$background = imagecreatetruecolor(130,130);//create the background 130x130
$whiteBackground = imagecolorallocate($background, 255, 255, 255); 
imagefill($background,0,0,$whiteBackground); // fill the background with white

imagecopyresampled($background, $this->_image,(130-$width)/2,(130-$height)/2, 0, 0, $width, $height, $width, $height); // copy the image to the background

ImageJpeg ($background,null,100); //display
Run Code Online (Sandbox Code Playgroud)

我已阅读多个帖子添加:

imagealphablending($background, false);
Run Code Online (Sandbox Code Playgroud)

进入应修复它的代码,但它没有任何区别.

提前致谢!

php gd resize

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

gd ×1

php ×1

resize ×1