473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GD Functions leaving lines in graphics

69 New Member
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....

Expand|Select|Wrap|Line Numbers
  1. header ("Content-type: image/png");
  2.  
  3. $bg = imagecreatetruecolor(100, 120);
  4. $back = imagepng($bg, "bg.png");
  5. $back = imagecreatefrompng("bg.png");
  6.  
  7. $color = 232;
  8. $x = 0;
  9.  
  10. while ($x < 120) {
  11. $im = imagecreatetruecolor(100, 5);
  12. $fill = imagecolorallocate($im, 0, 0, $color);
  13. imagefill($im, 0, 0, $fill);
  14. imagepng($im, "add.png");
  15. $one = imagecreatefrompng("add.png");
  16. imagecopy($back, $one, 0, $x, 0, 0, 100, 10);
  17. imagepng($back, "bg.png");    
  18. $x = $x + 5;
  19. $color = $color + 1;    
  20. imagedestroy($im);
  21. imagedestroy($one);
  22. }
  23. imagepng($back);
  24. imagedestroy($back);
  25. imagedestroy($bg);
  26. ?>
  27.  
  28.  
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?
Nov 12 '07 #1
2 1126
pbmods
5,821 Recognized Expert Expert
Heya, Lumpy.

Do you have a screenshot of what it looks like vs. what it's supposed to look like?
Nov 12 '07 #2
Lumpy
69 New Member
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!!!
Nov 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

99
5815
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
30
19667
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are...
2
20856
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
5
2715
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
9
3158
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
1
1169
by: Craig Lucas | last post by:
Im kind of new to vb.net drawing routines. Im reading a collection of 2d points from a proprietary file. These points are simply for drawing lines, I can draw the lines fine using...
35
2309
by: Francine.Neary | last post by:
I'm finding it really hard to keep some of these things straight... For example, fputs is to puts as fprintf is to printf, except that fputs has the file handle at the end and fprintf at the...
1
1718
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I want to make a "GRAPHICS PROGRAM" in C language that shows sorting of lines. Something like this:- ------------ ------------------- ------ ------------------------------------ after...
1
1991
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I want to make a "GRAPHICS PROGRAM" in C language that shows sorting of lines. Something like this:- ------------ ------------------- ------ ------------------------------------ after...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.