我试图修改此脚本:http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/白色背景调整图像
我希望得到一个(使用裁剪选项时),白色背景,而不是黑色的,因为它是现在。我的场景是这样的:
当我调整图像的大小时,我会在底部(1px)得到一个我不想要的黑色边框。我希望这是白色的。
我已经看过这个线程,并试图执行它的脚本:How do I fill white background while resize image
但它似乎并不工作。这里是我的调整大小类的代码:
public function resizeImage($newWidth, $newHeight, $option="auto")
{
// *** Get optimal width and height - based on $option
$optionArray = $this->getDimensions($newWidth, $newHeight, $option);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
// *** Resample - create image canvas of x, y size
$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
// MY EDIT STARTS HERE
$backgroundColor = imagecolorallocate($this->imageResized, 255, 255, 255);
imagefill($this->imageResized, 0, 0, $backgroundColor);
// AND STOPS HERE
imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
// *** if option is 'crop', then crop too
if ($option == 'crop') {
$this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
}
}
我在做什么错,我应该改变什么?
而且没有css? – 2012-04-08 12:29:19
没有设置CSS边框。这只是一些图像获取这个黑底部边界,其他人没有。这是 - 我认为 - 因为他们(没有底部黑色边框)有另一个宽度/高度比例,那么他们谁得到底部边框。 – Fredrik 2012-04-08 13:15:20