6
我有一个调整大小的图像脚本,需要一个130x81的图像,并将其添加到130x130的图像,该imagecopyresampled功能运行时,它增加了一个黑色的背景成剩下的空间,即使基本图像是白色的。下面的代码,我真的很感谢一些帮助。PHP imagecopyresampled增加了黑色背景
我试图合并到创建的130x130文件PHP中的形象是:
$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
我已经在多个帖子阅读补充:
imagealphablending($background, false);
到这应该修复代码它,但它没有任何区别。
在此先感谢!