Jump to content

GD colour problem.


helraizer

Recommended Posts

Hey folks, again.

 



if ($back == "m") //$back is a value pulled from a db; that works perfectly.
    {
        $wid = $rowing['width'];
        $hei = $rowing['height'];
        createthumb("660x240background2.gif", "./user/" . $user . "_back.gif", $wid, $hei);

        $image = imagecreatefromgif("./user/" . $user . "_back.gif");
        $blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
        $black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness
        $im = ImageCreate(300, 35);
        $black_a = imagecolorallocate($im, 0, 0, 0);
        $white_a = imagecolortransparent($im, $black_a);
        $white = ImageColorAllocate($im, 255, 255, 255);
        ImageFill($im, 0, 0, $white_a);
        Imagettftext($im, 15, 0, 10, 30, $white, $font, $user . "'s Shoutbox");

        $cur_line_y = 65; // This stores how far down the image the current line will print

        $postperpage = 11;
       }
elseif ($back == "u")
    {
        $wid = $rowing['width'];
        $hei = $rowing['height'];



        //        createthumb("./user/".$user."_img.gif", "./user/" . $user . "_backim.gif", $wid, $hei);

        imagecreatefromgif("./user/" . $user . "_img.gif");



        $images = imagecreate($wid, $hei);

        $imge = imagecreatefromgif("./user/" . $user . "_backim.gif");

        imagecopymerge($images, $imge, 0, 0, 0, 0, $wid, $hei, 20);

        imagegif($images, "./user/" . $user . "_back_trans.gif");

        $image = imagecreatefromgif("./user/" . $user . "_back_trans.gif");

$im = ImageCreate(300, 35);
        $black_a = imagecolorallocate($im, 0, 0, 0);
        $white_a = imagecolortransparent($im, $black_a);
        $white = ImageColorAllocate($im, 255, 255, 255);
        ImageFill($im, 0, 0, $white_a);
        Imagettftext($im, 15, 0, 10, 30, $white, $font, $user . "'s Shoutbox");
        
        $cur_line_y = 74; // This stores how far down the image the current line will print
        $postperpage = 10;
    }

$sql = ""; // no need for actuall SQL statement - it works.

$result = mysql_query($sql) or die("error in  sqllls: " . mysql_error());


$cur_line_x = 24; // This stores how far across the image the current line will print
$pagecharwidth = 75; // this is the maximum length of the line before it wraps;
$lineheight = 18; // This is how much to move down to print the next line
$pagelinelimit = 1; // How many of each comment appears per page.


//ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black);

$numberOfLines = $pagelinelimit;

for ($i = 0; $i < $numberOfLines; $i++)
{
    while ($row = mysql_fetch_array($result))
    {

        $name = "[" . htmlspecialchars_decode($row['username']) . "] "; //it works - returns username
        $font = $row['font']; //it works - renders the colour
        $color = $row['color']; //it works - changes the font
        $line = htmlspecialchars_decode($row['comment']); //it works, posts the shout

if ($name == "[] ")
        {
            $name = "";

            $line = $name . $line;
        }
        else
        {
            $line = $name . $line;

        }

//code for emoticons.

//add shouts to image!
        if ($back == "m" )
        {
            if ($color == "white" || $color == "yellow" || $color == "green" || $color ==
                "orange" || $color == "aqua")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }
            elseif ($color != "white" || $color != "yellow" || $color != "green" || $color !=
                "orange" || $color != "aqua")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font),
                    trim($line));


            }
            elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
                "timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }
            else
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
                    ($line));


            }

        }
        elseif ($back == "w" )
        {

            $blac = imagecolorallocate($image, 0, 0, 0);

            if ($color == "black" || $color == "purple" || $color == "blue" || $color ==
                "emerald" || $color == "red")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }
            elseif ($color != "black" || $color != "purple" || $color != "blue" || $color !=
                "emerald" || $color != "red")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $blac, getfont($font),
                    trim($line));


            }
            elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
                "timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }
            else
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
                    ($line));


            }

           }


 

Depending on the values of $back, the background of the image changes and the font colours also change. This code works so far.

 

Problem code

 

elseif($back == "u")
           {
		   if ($color == "white" || $color == "yellow" || $color == "green" || $color ==
                "orange" || $color == "aqua")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }elseif ($color != "black" || $color != "purple" || $color != "blue" || $color !=
                "emerald" || $color != "red")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font),
                    trim($line));


            }
            elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
                "timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
            {
                Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
                    ($font), trim($line));


            }
           else
           {
               Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
                 ($line) . "    ");


           }
	}
    
        $cur_line_y += $lineheight;


    }
}

 

The problem is that when $back == "u", for the first two comments the colours are normal then after that the older comments turn black; the newest comment is in colour but it also changes the colour of the $im that says "User's Shoutbox", which is created as a seperate image.

 

I can't, for the life of me, see the problem.. can you?

 

An example: The oldest comment was white, then I added the Yellow comment, the white one turned black.

 

lucifer.gif

 

Hope that makes sense,

Sam

Link to comment
Share on other sites

W00t, triple post.

 

Anyways. I've fixed it now!

 

It's always the simple things.. I used imagecreatetruecolor($wid, $hei); instead of imagecreate(); and it works perfectly now. Before, because of the photo background, I was running out of colours (so to speak). It works poifectly now.

 

Sam

Link to comment
Share on other sites

quadruple post. xD

 

The imagecreatetruecolour only solved it for a little while, allowing one more comment of colour than before, now the comments do the same thing.

 

Any ideas why when a new comment is posted, the imagecolorallocate fails and the comments turn black?

 

supposed to be like:

 

helraizer.gif - plain background, colours work!

 

but ends up like:

 

lucifer.gif - detailed background, colours only work part of the time.

 

Please reply if you have any theories.

 

Sam

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.