Re: GD : Black background with imagecreatetruecolor

From: Date: Thu, 21 Nov 2002 22:26:39 +0000
Subject: Re: GD : Black background with imagecreatetruecolor
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-125523@lists.php.net to get a copy of this message
Yeah !!! It works Thanks Morgan Arnaud "Morgan Hughes" <kyhm@kyhm.com> a écrit dans le message de news: Pine.WNT.4.44.0211211341040.1156-100000@kitsune... > On Thu, 21 Nov 2002, Arnaud wrote: > > > Hi everyone, > > I'd like to use "imagecreatetruecolor" function in order to "cut and paste" > > JPG files on a white background. It seems not to work correctly. > > This one bit me when I started working with GD 2.x as well. Simply draw > a filled rectangle over your entire canvas in the color you want: > > <? > $im=imagecreatetruecolor(50,50); > $COULEUR_BLANC=imagecolorallocate($im,255,255,255); > imagefilledrectangle($im,0,0,49,49,$COULEUR_BLANC); > header ("Content-type: image/png"); > ImagePNG($im); > imagedestroy($im); > ?> > > The reason seems to be that when you create an indexed-color image > (imagecreate()) gd sets all pixels to index 0, and when you allocate > your first color, that's index 0. Thus all background pixels magically > become that color. > > When you use imagecreatetruecolor(), it sets all the pixels to black, > and you have to explicitly draw them in to get them white. > > -- > Morgan Hughes > C programmer and highly caffeinated mammal. > kyhm@kyhm.com > ICQ: 79293356 > > >

« previous php.general (#125523) next »