<?
$url 
$_REQUEST[url];
$x $_REQUEST[x];
$y $_REQUEST[y];
if ( isset(
$url) )
{
if ( !
preg_match("#php|jpg|jpeg|png|jpe|gif$#i"$url) )
{
die(
"
<html>
<head>
<title>Grabber - Sizer</title>
</head>
<body bgcolor=#ffffff text=#000025>
<br>
<h1>Invalid file type</h1>
</body>
</html>"
);}}
?>
<html>
<head>

<script type="text/javascript">
<!--
//Xlectric Script
function setUp()
{
var w_tv = navigator.appName.indexOf("WebTV") != -1;
var h_p = history.previous;
if (w_tv && h_p.substring(0, 4) == "http")
{
document.forms["cgrab"].elements["url"].value = h_p;
}
}
//-->
</script>

<title>Grabber - Sizer</title>

</head>

<body bgcolor="#ffffff" text="#000025" link="#000025" vlink="#000025" onload="setUp();">

<br>
<span style="font-family: 'Trebuchet MS', Arial, sans-serif; color: #000025; font-size: 24px; font-weight: bold; text-align: center;">Color Grabber - Sizer - Coordinate Saver</span> <span style="font-family: 'Trebuchet MS', Arial, sans-serif; color: #000025; font-size: 12px; text-align: center;">by DJ Mike</span>

<br>
File types: .gif, .jpg, .jpeg, .jpe,  .png
<form action="" name="cgrab" method="get">
<?
# Pass $url to stage 2 as hidden input
if ( isset($url) )
{ echo 
"<input type=\"hidden\" name=\"url\" value=\"$url\" />"; }
?>
<table align="center" width="" border="1">
<tr>
<td align="center">
<input type="text"  value="<?
if ( !isset($url) )
{ echo 
"http://"; }
if ( isset(
$url) )
{ echo 
"$url"; }
?>" name="url" />
<input type="submit" value="Load Image">
<br> 
</td>
</tr>
<tr>
<td align="center">
<?
#### if $url entered, find size ####
if ( isset($url) )
{
echo 
"<center>Click image below for coordinates and colors.</center>\n";
list(
$width$height$type$attr) = getimagesize("$url");
$string file_get_contents($url);
$length strlen($string);
echo 
"<center><textarea growable cols=\"85\" rows=\"15\" growable border=\"0\"><img src=\"$url\" $attr />\n\n";
echo 
"$length bytes\n\n";

#### if image clicked, find coordinates ####
if ( isset($x) && isset($y) )
{ echo 
"Coordinates\nx=$x y=$y\n\n"

#### find image type from list() above ####
if ( $type == )
$im imagecreatefromgif($url); }
if ( 
$type == )
$im imagecreatefromjpeg($url); }
if ( 
$type == )
$im imagecreatefrompng($url); }
$color_index imagecolorat($im$x$y);
#### show colors as % ####
$color_tran imagecolorsforindex($im$color_index);
echo 
"Colors as %\n";
echo 
"red = $color_tran[red]\n";
echo 
"green = $color_tran[green]\n";
echo 
"blue = $color_tran[blue]\n";
echo 
"alpha = $color_tran[alpha]\n\n";
echo 
"CCP colors below\n";
echo 
"'rgb($color_tran[red],$color_tran[green],$color_tran[blue])'\n";
#### convert colors to hex ####
$red dechex($color_tran[red]);
$green dechex($color_tran[green]);
$blue dechex($color_tran[blue]);
#### if color is only one digit, append a zero ####
if ( strlen($red) == 1)
$red "0" $red; }
if ( 
strlen($green) == 1)
$green "0" $green; }
if ( 
strlen($blue) == 1)
$blue "0" $blue; }
#### concatenate colors ####
$rgb "$red" "$green" "$blue";
echo 
"Color in hex = '#$rgb'\n\n";
#### if gif, show number of colors ####
if ( $type == )
{
$num_colors imagecolorstotal($im);
echo 
"Number of colors = $num_colors\n";
}
}
echo 
"</textarea>";
echo 
"<br><br>";
echo 
"<input type=\"image\" src=\"$url\" cursor></center>";
}
#### if no url entered, show prompt ####
if ( !isset($url) )
{
echo 
"<center>no image loaded</center>";
}
echo 
"<br /><br /><br />";
$filetext "Coordinates.txt";
$spc "\r";
$fp fopen ($filetext"a"); 
$coord="$x,$y";
if (
$fp) {
fwrite ($fp$coord); 
fwrite ($fp$spc); 
fclose ($fp);
}

echo 
"Your coordinates have been entered. <br />";
echo 
"Go to <a href=\"Coordinates.txt\">Coordinates.txt</a> and reload the page to see your entries.";
?>

</td>
</tr>
</table>
</form>
</body></html>