SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Feb 5, 2005, 08:41 #1
- Join Date
- Apr 2001
- Location
- London, UK
- Posts
- 59
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A more efficient color gradient function?
I currently am trying to make a simple image using php. I have got everything working, except the color gradient function i am using does not seem to work very well. There seems to be 'noise' in the font when the image gradient is applied. To demonstate i have attached an image of wat i mean:
Note that there are pixels 'missing' when the gradient function is applied to the background. Specially if you look at the 's' of Sat. It is apparent in other places too if you look carefully. Im not sure why this is, or if it can be prevented, but i would be grateful if someone with more knowledge than me could advise me on this, or provide me with a function which can do the gradient better.
The code was taken off the php.net site, i have tried their other functions, but they dont seem to work for me. Also, i dont know why the last box doesnt even have a proper gradient to it?
PHP Code:function imagecolorgradient($img,$x1,$y1,$x2,$y2,$f_c,$s_c){
sscanf($f_c, "%2x%2x%2x", $red, $green, $blue);
$f_c = array($red,$green,$blue);
sscanf($s_c, "%2x%2x%2x", $red, $green, $blue);
$s_c = array($red,$green,$blue);
if($y2>$y1) $y=$y2-$y1;
else $y=$y1-$y2;
if($f_c[0]>$s_c[0]) $r_range=$f_c[0]-$s_c[0];
else $r_range=$s_c[0]-$f_c[0];
if($f_c[1]>$s_c[1]) $g_range=$f_c[1]-$s_c[1];
else $g_range=$s_c[1]-$f_c[1];
if($f_c[2]>$s_c[2]) $b_range=$f_c[2]-$s_c[2];
else $b_range=$s_c[2]-$f_c[2];
$r_px=$r_range/$y;
$g_px=$g_range/$y;
$b_px=$b_range/$y;
$r=$f_c[0];
$g=$f_c[1];
$b=$f_c[2];
for($i=0;$i<=$y;$i++){
$col=imagecolorallocate($img,round($r),round($g),round($b));
imageline($img,$x1,$y1+$i,$x2,$y1+$i,$col);
if($f_c[0]<$s_c[0]) $r+=$r_px;
else $r-=$r_px;
if($f_c[1]<$s_c[1]) $g+=$g_px;
else $g-=$g_px;
if($f_c[2]<$s_c[2]) $b+=$b_px;
else $b-=$b_px;
}
return $img;
}
-
Feb 5, 2005, 08:48 #2
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Shaq
Can you do images with text on a solid background?
DouglasHello World
-
Feb 5, 2005, 10:03 #3
- Join Date
- Apr 2001
- Location
- London, UK
- Posts
- 59
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Both those images are produced on the same server using the same script. At the top, ive taken out the backgrounds, so its sitting on white bg... the bottom one is the one including the gradient in the background.
The whole point is the get the text on the gradient background... is there any way to force anti-aliasing or something?
-
Feb 5, 2005, 11:28 #4
Shaq: There are several bugs with anti-aliasing in php's bundled version of GD(atleast there was when I used AA with it a while ago).
-
Feb 7, 2005, 06:58 #5
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- Posts
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A few months ago, My boss and I were playing with GD to render text because our client needed headings in a set font. We had a LOT of problems with the GD font system. You will find that Linux servers tend to be compiled have a different DPI from Windows and Mac systems, so quite often the text distorts. Also, the ttfbox commands tend to be a bit random in the way they work, and the kerning screws up as well in Linux.
What you normally need to do is recompile GD without the bundled library. In gd.h at the end of the file there is a constant for the DPI. I think that needs to 72 DPI and not 96 (otherwise the font size will be different if you use a Mac or windows PC to develop one, like I do).
Remember, if you recompile GD, don't forget to compile libPNG, libJPEG, and all other other dross that it depends on. You also need to play around a lot with the command line ./configure options. As a result I recommend that you compile as a shared .so file (anotherwords, use use phpize)
Bookmarks