473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

imagesetpixel() Troubles

I'm trying to make a PHP script that increases the blue value of each pixel in an image by 1.
It's important that the script goes pixel by pixel.
For some reason, however, it outputs an image that is one solid color; a brownish red block.
Why isn't this script only slightly increasing the values?? ??? ???



Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $img = imagecreatefromgif('logo.gif');
  3.  
  4. // get height and width
  5. $h=imagesy($img);
  6. $w=imagesx($img);
  7.  
  8. //display image
  9. echo "<img src='out.gif' />";
  10.  
  11. //cycle through every pixel and add 1 to the blue value of the pixel's rgb value
  12. $y=1;
  13. while($y < $h) {
  14. $x=1;
  15. while($x < $w) {
  16.  
  17. $rgb = imagecolorat($img, $x, $y);
  18. $red = ($rgb >> 16) & 0xFF;
  19. $green = ($rgb >> 8) & 0xFF;
  20. $blue = $rgb & 0xFF;
  21. $blue++;
  22.  
  23. //define the new color and assign it to the pixel
  24. //this is where things go wrong
  25. $color = imagecolorallocate($img, $red, $green, $blue);
  26. imagesetpixel($img, $x, $y, $color);
  27. $x++;
  28. }
  29. $y++;
  30. }
  31.  
  32. echo imagegif($img, 'out.gif');
  33. ?>
I know the problem is in these two lines by the way.
Expand|Select|Wrap|Line Numbers
  1. $color = imagecolorallocate($img, $red, $green, $blue);
  2. imagesetpixel($img, $x, $y, $color);
Feb 24 '08 #1
1 1683
MarkoKlacar
296 Expert 100+
Hi,

Not quite sure what you're doint on line 9., you're displaying the image before anything has been done to it.

Is there a way for you to post the original picture and the result picture?

Thanks
Feb 26 '08 #2

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

Similar topics

33
by: Darren Dale | last post by:
I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what...
0
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
3
by: Mr. B | last post by:
GRRRR... I've run across a situation in which I have NO solution. Hopefully there is one. VB.net. It's rather simple. I've a ComboBox that get's populated via a Database. And I pre-select...
4
by: jernej goricki | last post by:
Hy I'm trying to edit a XSLT document, just like I'm editing a XML document : (Im trying to make a new xsl:template tag here ) Dim myXml As New XmlDocument()...
4
by: Edwin G. Castro | last post by:
I want to start a process from a C# application. I also want to redirect standard error to standard output so that I can read output from both streams just like I could from a command line. In...
0
by: Stefan Slapeta | last post by:
Hi all, I've experienced some troubles with message tables and wanted to know if anybody knows a solution for one of them: - If I translate my .mc file into a Unicode .bin file, some of the...
0
by: Michal | last post by:
I have troubles with instaling .Net Framework 2.0 (Beta 2 - 2.0.50215). The main instalation went just fine, troubles begin with my attemt to run aspnet_regiss.exe -i. Asp.Net is instaled into IIS...
0
by: JohnIdol | last post by:
VC++6 to VC++2003 - linking troubles -------------------------------------------------------------------------------- Hi All, I successfully ported an application from VC++6 to VS2003. Solved...
1
by: Pegasus | last post by:
Good morning, I'm Filippo Battaglia. We're porting Apache STDCXX under Nanodesktop. We are trying to make nd compatible also with C++ and not only with C. Unfortunately, we're finding different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.