このスクリプトを変更しようとしています:http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
(トリミングオプションを使用する場合)現在のように、黒ではなく白の背景を取得したいと思います。私のシナリオはこれです:
画像のサイズを変更すると、下部(1px)に不要な黒い境界線が表示されます。代わりにこれを白にしたい。
私はこのスレッドを調べて、スクリプトに実装しようとしました:画像のサイズを変更しながら白い背景を塗りつぶすにはどうすればよいですか?
しかし、それはうまくいかないようです。サイズ変更クラスのコードは次のとおりです。
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);
}
}
私は何を間違っているのですか、そして何を変えるべきですか?