Solved

Image creation via PHP

Posted on 2003-11-24
11
298 Views
Last Modified: 2010-04-17
Hi, I  have recently been working on a script which will create an image via PHP, but seems to have stumbled upon a big error.

My script is..

<?

if($ploc=="Hev") { $im = imagecreatefrompng('Hev.png'); }
else if($ploc=="Sky") { $im = imagecreatefrompng('Sky.png'); }
else if($ploc=="Sur") { $im = imagecreatefrompng('Sur.png'); }
else if($ploc=="Dun") { $im = imagecreatefrompng('Dun.png'); }
else if($ploc=="Hel") { $im = imagecreatefrompng('Hel.png'); }

      $kdc=0;
      $kds=0;

      ?>
            <script language="JavaScript" type="text/javascript">
                  function loc(x,y) { s_Loc.innerHTML="Location: "+x+","+y; }
                  function ut() { s_Loc.innerHTML="<br>"; }
                  function kd(kdnum) { s_KD.innerHTML=kdnum; }
                  function kds(kdnum) { s_KDS.innerHTML=kdnum; }
            </script>
      <?

      echo "Number of kingdoms: <span id=s_KD>".$kdc."</span> || Kingdoms Checked: <span id=s_KDS>".$kds."</span><p><span id=s_Pic>Old :: <br><img src=result.jpeg></span><p>";

$width=300;
$height=300;

$image=imagecreate($width,$height);
$bg=imagecolorallocate($image, 0x00,0x00,0x00);

for ($i=0;$i<300;$i++){
      for ($j=0;$j<300;$j++){
            $start_x = $j;
            $start_y = $i;
            $color=imagecolorat($im, $start_x, $start_y);
            if($color==$colour) {
                  $kdc++;
                  imagesetpixel($image,$start_x,$start_y,$color);
            }
            $kds++;
      }
      echo "<script>kds(\"".number_format($kds)."\");</script>";
      echo "<script>kd(\"".number_format($kdc)."\");</script>";
}

imagejpeg($image,"result.jpeg");
imagedestroy($image);

echo "<p>New :: <br><img src=result.jpeg>";

?>

The imagesetpixel() seems to not be working at all and therefore it prints a fully black image. This shouldn't happen. Can anyone suggest a fix? (based on the above script). Quickest and most efficient answer gets..... ooooohh.... 75 points?

EDIT: Upped to 100
0
Comment
Question by:Vampireofdarkness
  • 5
  • 4
11 Comments
 
LVL 8

Expert Comment

by:_corey_
Comment Utility
Where is $colour defined?

Have you verified the color value and the fact that imagesetpixel even gets called?
0
 
LVL 9

Author Comment

by:Vampireofdarkness
Comment Utility
Oh, sorry.
   $colour is a variable from a previous page (appears in /xx.php?colour=xx)
   $ploc is also the same
0
 
LVL 9

Author Comment

by:Vampireofdarkness
Comment Utility
and imagesetpixel does get called as it shows that there are 10,144 color matches
0
 
LVL 9

Author Comment

by:Vampireofdarkness
Comment Utility
Found a solution for myself... now to close this....

Thanks for your help anyway
0
 
LVL 8

Expert Comment

by:_corey_
Comment Utility
I believe posting on the CS area will get it removed for you.

Was it a bad setting of $colour or something else?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Author Comment

by:Vampireofdarkness
Comment Utility
All I needed to do was define $colour before the loop with

$black=imagecolorallocate($image, 0x00,0x00,0x00);

for a black colour, etc..etc.. then use those colours.
0
 
LVL 8

Expert Comment

by:_corey_
Comment Utility
Ah, so $colour was simply being defined in the loop and constantly matching up with the value of black?
0
 
LVL 9

Author Comment

by:Vampireofdarkness
Comment Utility
$colour wasn't being defined, for some reason although it should have been. Which is why it posted black.
0
 
LVL 8

Expert Comment

by:_corey_
Comment Utility
That's what I had suspected when I saw it wasn't defined.  It was being defined with a default nothing value and so then black always matched with it.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
Comment Utility
PAQed, with points refunded (100)

Computer101
E-E Admin
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now