Messing with the image functions

He has: 296 posts

Joined: May 2002

Hey everyone,

I'm trying to figure out the image functions in PHP and I wrote a script. It's supposed to load an image specified in the URL, store the color at every pixel in a variable, then echo it out as HTML. Just something odd I felt like wasting my time with. But it doesn't. It just loads forever.

Code:

<?php
 
if (!isset($pic)) $pic = 'default.jpg';

$im = imagecreatefromjpeg($pic);
if (!
$im)
{
  echo
'Error loading image!';
  exit;
}
$crapol = getimagesize($pic);
$size[height] = $crapol[1];
$size[width] = $crapol[0];
$i = 1;
$i2= 1;
while (
$size[height]>=$i)
{
  if (
$size[width]>=$i2)
  {
   
$colorat[$i][$i2] = imagecolorat($im,$i,$i2);
   
$i2++;
  }
  else
  {
   
$i++;
   
$i = 1;
  }
}
$height='0';
$width='0';

while(
$height<=$size[height])
{
  echo
$colorat[$height][$width];
 
$colors = explode(\",\",$colorat[$height][$width]);
 
$red    = $red+1;
 
$green    = $green+1;
 
$blue    = $blue+1;
 
$red2   = $red;
 
$green2 = $green;
 
$blue2  = $blue;
 
$r      = '1';
 
$g      = '1';
 
$b      = '1';
 
$hexidecimals = '0,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F';
 
$hex = explode(\",\",$hexidecimals);
  while (
$red2 > '16')
  {
     
$red2 = $red2-16;
     
$r++;
  }
  while (
$green2 > '16')
  {
     
$green2 = $green2-16;
     
$g++;
  }
  while (
$blue2 > '16')
  {
     
$blue2 = $blue2-16;
     
$b++;
  }
 
$colour[1] = $hex[$red2];
 
$colour[2] = $hex[$r];
 
$colour[3] = $hex[$green2];
 
$colour[4] = $hex[$g];
 
$colour[5] = $hex[$blue2];
 
$colour[6] = $hex[$b];
 
$haha = ''.$colour[1].$colour[2].$colour[3].$colour[4].$colour[5].$colour[6].'';
echo<<<MyDIV_
    <div style='height: 1px; width: 1px; background-color: ; position: absolute; top:
$height; left: $width;'>
    </div>
MyDIV_;
  if (
$width<=$size[width])
  {
   
$width++;
  }
  else
  {
   
$height++;
   
$width='0';
  }
}
?>

I know it's not the BEST way to do it, but since it's just for my personall testing and crap I don't really care Smiling. Any help is greatly appreciated.

out,
necrotic

[James Logsdon]