GD Functions leaving lines in graphics

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lumpy
    New Member
    • Oct 2007
    • 69

    GD Functions leaving lines in graphics

    Ok all, I have a question regarding the gd library in php. First, let me say that there is really no reason why I am doing this the way that I am. I was a little bored with doing homework and thought to myself, hey I wonder if I can put a background images into parts of a webpage using css pointing to php files. So I set out to answer the question that was burning away at me... :)

    Anyways, here is the code I am using to create the background for the top of a web page, 120px high. The final png is made up of smaller 5px high pngs that have a slight color change, giving the final effect of a little fade, if you will....

    [CODE=php]
    header ("Content-type: image/png");

    $bg = imagecreatetrue color(100, 120);
    $back = imagepng($bg, "bg.png");
    $back = imagecreatefrom png("bg.png");

    $color = 232;
    $x = 0;

    while ($x < 120) {
    $im = imagecreatetrue color(100, 5);
    $fill = imagecoloralloc ate($im, 0, 0, $color);
    imagefill($im, 0, 0, $fill);
    imagepng($im, "add.png");
    $one = imagecreatefrom png("add.png");
    imagecopy($back , $one, 0, $x, 0, 0, 100, 10);
    imagepng($back, "bg.png");
    $x = $x + 5;
    $color = $color + 1;
    imagedestroy($i m);
    imagedestroy($o ne);
    }
    imagepng($back) ;
    imagedestroy($b ack);
    imagedestroy($b g);
    ?>

    [/CODE]

    Now the problem I run into intermittently is that every so often when the page loads, it doesn't render all the lines into the final png correctly. The color gets messed up in the smaller image and then the messed up smaller image gets added into the final image having the wrong color.

    Any thoughts on why this might be or what is causing this?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Lumpy.

    Do you have a screenshot of what it looks like vs. what it's supposed to look like?

    Comment

    • Lumpy
      New Member
      • Oct 2007
      • 69

      #3
      Originally posted by pbmods
      Heya, Lumpy.

      Do you have a screenshot of what it looks like vs. what it's supposed to look like?
      So, I got the problem solved. I was in the process of making some screen shots that I would be able to post, so you would be able to see what I was doing and what I meant by the problem I was having. When I noticed a little pattern. When the lines showed up in the overall png, It matched up with another part of the site, in which I am also using the same process to make the background. Noticing this I examined the code from both files again, and realized that I was using the same file name for the temp png, "add.png", opps. What was happening was it was grabbing the wrong "add.png" and inserting it into the whole png. Long story short, I changed the temp file name and now everything works perfectly.

      Thank You for your inspiration!!!

      Comment

      Working...