Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagescreatetruecolor with a white background

Tags:

php

image

I'm pretty sure I need to use imagefilledrectangle in order to get a white background instead of black on this... just not sure how. I've tried a few ways.

$targetImage = imagecreatetruecolor($thumbw,$thumbh);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbHeight,imagesx($sourceImage),imagesy($sourceImage));
like image 876
Jean-Pierre Bazinet Avatar asked Nov 15 '11 11:11

Jean-Pierre Bazinet


People also ask

How to make background transparent in PHP?

The imagecolortransparent() function is an inbuilt function in PHP which is used to define color as transparent. It sets the color of a transparent image. It returns the identifier of the new transparent color. If an image has no transparent color and color not specified then it returns -1.

How to set background colour to an image in PHP?

$image = imagecreatetruecolor(500, 300); // Set the background color of image. $bg = imagecolorallocate( $image , 205, 220, 200);

What is imagecreatetruecolor?

The imagecreatetruecolor() function is an inbuilt function in PHP which is used to create a new true-color image. This function returns a blank image of the given size.

What is Imagecolorallocate PHP?

The imagecolorallocate() function is an inbuilt function in PHP which is used to set the color in an image. This function returns a color which is given in RGB format. Syntax: int imagecolorallocate ( $image, $red, $green, $blue )


1 Answers

UPDATE (2020): Please see this answer below for a faster fill than imagefill: https://stackoverflow.com/a/32580839/1005039

ORIGINAL

From the PHP manual entry for imagefill:

$image = imagecreatetruecolor(100, 100);

// set background to white
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
like image 97
Gustav Bertram Avatar answered Nov 03 '22 06:11

Gustav Bertram