我試圖修改此腳本: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