のサイズを変更します。私のシナリオは次のとおりです:白い背景には、私は、このスクリプトを変更しようとしている画像
イメージのサイズを変更すると、私は望ましくない黒い境界線(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境界線が設定されていません。この黒いボトムボーダーを取得するのはちょっとしたイメージですが、他の人はそうしません。これは - 私が思うものです - なぜなら彼らは黒い境界線を持たないので、下の境界線を取る人は幅と高さの比率が違うからです。 – Fredrik