The function is when users upload a picture, program will generate a new white background squre image, and put user's picture in the center of this image.
But the problem is, I set the background to white, it always shows black.
The code is
$capture = imagecreatetruecolor($width, $height);
$rgb = explode(",", $this->background);
$white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]);
imagefill($capture, 0, 0, $white);
and the code that controls the color is
protected $background = "255,255,255";
I've been tried to change $white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]);
to $white = imagecolorallocate($capture, 255, 255, 255);
. But the background still shows in black.
Thanks for any answer
From the manual imagecreatetruecolor() returns an image identifier representing a black image of the specified size.
The first call to imagecolorallocate sets the background for palette based images but a true color image is not.
The way I set the background color on true color images is to just fill it with a solid rectangle.
imagefilledrectangle($capture, 0, 0, $width, $height, $white);
what about imagefill($im, x, y, $color)
?
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
This will fill entire image with red color, and the x,y
parameters are the starting point of rectangle fill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With