Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question gd pixel color value ends up all blue and dark

    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:

    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);
    
    ?>

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    this is the problem area, but whats the problem?

    Code:
    $rgb = imagecolorat($img, $i, $j);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;
    
    ...
    
    echo("background:rgb(".$r.",".$g.",".$b.");");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •