...

View Full Version : gd pixel color value ends up all blue and dark



singedpiper
07-07-2005, 03:41 AM
don't ask why, but I'm trying to write a script to convert a small image to a series of styled divs that each represent 1 pixel... i.e. rendering an image as styles and html ONLY...

I thought it would be cool to create a website (just as an experiment) with all the styles of a pro site, but with only 1 ascii file...

the only problem is the image shows up in only deep blue and black.

here is code:



<?php
$filename="image.gif";

$output = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n<META http-equiv=\"Content-Type\"
content=\"text/html; charset= ISO-8859-1\">\n<style type=\"text/css\">\n\n\n.pic\n{\n\t position: relative;\n}\n.px\n{\n\n\t position: absolute;\n\t font-size:10px;\n\t width: 1px;\n\t height: 1px;\n\t overflow:
hidden;\n}\n</style>\n</head>\n<body>\n\t<div class=\"pic\">\n";

$img = imagecreatefromgif("$filename");
if(!$img)
{
echo "broken";
exit(0);
}
$imagex = imagesx($img);
$imagey = imagesy($img);
for($i=0;$i<$imagex;$i++)
{
for($j=0;$j<$imagey;$j++)
{

$rgb = imagecolorat($img, $i, $j);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$output .= "<div class=\"px\" style=\"background:rgb(".$r.",".$g.",".$b.");color:rgb(".$r.",".$g.",".$b.");top:".$j."px;left:".$i."px;\">.</div>\n";
}
}
$output.="\t</div>\n</body>\n</html>";

echo ($output);

?>

singedpiper
07-07-2005, 04:06 PM
this is the problem area, but whats the problem?



$rgb = imagecolorat($img, $i, $j);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

...

echo("background:rgb(".$r.",".$g.",".$b.");");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum