I'm trying to modify this script: http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/
I want to get a (when using the crop option) white background instead of black, as it is now. My scenario is this:
When I resize an image I get a black border at the bottom (1px) which I don't want. I want this to be white instead.
I have looked in this thread and tried to implement it on the script: How do I fill white background while resize image
But it doesn't seems to work. Here is my code for the resize class:
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);
}
}
What am I doing wrong and what should I change?