Forum Moderators: coopster

Message Too Old, No Replies

gd weird colors

         

bleak26

12:05 am on Oct 19, 2004 (gmt 0)

10+ Year Member



I have been trying to edit an image and add text to it , i have sucseeded , but the color of the text had changed from black to yellow.

so i added the code bettween the lines of stars, which gets rid of the black, where it should do, but makes it blueish/grey and the font color remains the same.

please could you tell me why this is happening and how to make it display my text as black and transparency as transprent.

<?php
header ('content-type: image/png');
$im = imagecreatefrompng('bars/title_test.png');

********************************************
// added here got rid of black border, but it did not //make the fill white, like the back ground
imageAlphaBlending($im, true);
imageSaveAlpha($im, true);
// ************************

$fontpath = '/usr/www/users/mimi7818/fonts/';
$texttobeadded = "test text for button";
$x = 10;
$y = 30;
$color = imagecolorallocate ($im, 0,0,0);
imagettftext ($im,30,0,$x,$y,$color,'/usr/www/users/mimi7818/fonts/HIROSHT.TTF', $texttobeadded);

imagepng ($im);
?>

[edited by: jatar_k at 4:55 am (utc) on Oct. 19, 2004]
[edit reason] removed links [/edit]

mincklerstraat

7:15 am on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bleak, I've had untold headaches trying to get images do transparency right with my scripting. I found that some images would work and be transparent where they were supposed to, and some wouldn't, and just show black or white where the transparent part was supposed to be.

I suspected that this difference probably had to do with how the images were constructed and saved in graphics editors. It's possible to save the background color of a transparent background in gimp, for example.

Worst of all, I found that this behavior of transparent stuff changed when moving from platform to platform. What worked lovely in my rather irkish GD2 install on Debian (irkish: doesn't have imagerotate or imagecreatefromgif) refused to work on my host's install of GD2 on Red Hat. Hooorah.

At this point, there's not much I can do for you except commiserate a bit. Maybe there's a bigger gd wiz on these boards who can help the both of us here with a truly golden tip.

I can offer some very klugey advice, though, so here it is. You might try turning off imagealphablending once you've already printed out your text on the png, and maybe turning off imagesavealpha. Try juggling around these values, turning it on here, turning it off there, and seeing what you get.

For my script, I encouraged users to upload graphics without transparency, and since mine also did weird stuff with png and gif in an area that was added on to the bottom of the image, I actually give them the option of changing their image to jpeg format, which solved these issues. So they see their image as uploaded with the stuff that gd does, and if they don't like it, they click on 'switch to jpeg' and it looks better again.

Good luck.