note 12407 deleted from function.imagettftext by jimw

From: Date: Mon, 17 Dec 2001 22:36:53 +0000
Subject: note 12407 deleted from function.imagettftext by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23041@lists.php.net to get a copy of this message
I noticed that ImageTTFText seems to blend colours instead of what was specified. So with a bit of trial and error I came up with this formula. The delivered color is 3/4 of the background color + 1/4 of the font color. WRT the RGB values of each. Now, I experimented with values > 255 and < 0 and it still works ! I wrote this routine to make life easier for myself. function getTTFFontColor($im,$red,$green,$blue,$samplex=null,$sampley=null) { if (!isset($samplex)) { $samplex=ImageSX($im)/2; $sampley=ImageSY($im)/2; } $bgcolor=imagecolorsforindex($im,imagecolorat($im,$samplex,$sampley)); $fontcolor['red']=($red-(0.75*$bgcolor['red']))*4; $fontcolor['green']=($green-(0.75*$bgcolor['green']))*4; $fontcolor['blue']=($blue-(0.75*$bgcolor['blue']))*4; return $fontcolor; } If you don't pass $samplex and $sampley then it uses the centre of the image to get the background color. Enjoy.

« previous php.notes (#23041) next »