A Long Shot, But Might As Well Ask

Soldato
Joined
10 Dec 2003
Posts
6,348
Is there any such tool you know about, that can take an image, count every pixel, get the hex colour value of each pixel and then output all those values as text?

Would it even be possible to do something like this? I'm guessing you can't, but would it be possible in PHP?

I have something very interesting I want to do, but zooming into an image and getting every pixel value is extremely tiresome and slow. Does anyone have any ideas on how I could automate this process?

Thanks.
 
You'd need to start with an uncompressed image - BMP, TIFF etc.

http://en.wikipedia.org/wiki/BMP_file_format

There's some decent info in there, not quite sure what the best way of stripping the header and turning the rest into hex though.

EDIT: This might be easier than it looks - just opened up a .bmp in a Hex mode text editor and it's quite simple to see what's header and what's data. You'd just need to interpret the header to get the colour depth of the image so that you know how many bytes represent each pixel.
 
Last edited:
yeah im sure someone on here could knock up a quick program for this. I would in C++ but i have a lot of work to do myself right now! sorry. But yes, very possible :p
 
just out of curiosity what do you need this for? if you can't say fair enough, maybe other people can say why they know of it and how anyone would ever want to use this? i can't think of one possible reason
 
Please tell me it's not to store in a database, then convert back again at a later date..

I'm thinking of implementing it so I can save images to the database pixel by pixel then redrawing them. I like to call it anti-caching
 
Haha, nope - it's not to store an image pixel by pixel in a Database. :p

I need a list of RGB colours that are taken from an image starting from the top left, and reading to the bottom right. The idea then, is to create a div with a class value (ex. x10y7) would mean 10 across and 7 down.

So then I need to autogenerate a list, like so:

Code:
<div class="[imagename] x10y9"></div>

with autogenerated CSS that accompanies it, such as:

Code:
div.x10y9 {
	position: relative;
	width: 1px;
	height: 1px;
	float: left;
	background-color: (Insert value, relative to the name);
}

So the idea then, is that if I have a 640x480px image, I could duplicate that image pixel by pixel with DIVs, 1px in size and with the appropriate background color.

Then I can get to work on making it useful, which I wil share once done. ;) - providing I can acheive what I'm thinking.
 
Here's a mock-up I currently have. It would be great if it was all done in PHP, as I plan for it to be a web-based application in the end.

Code:
<?php

	$source = ImageCreateFromPng("css/images/cutepixel.png");

	$x = 18;
	$y = 20;

	$rgb = imagecolorat($source, $x, $y);
			
		$red = ($rgb >> 16) & 0xFF;
		$green = ($rgb >> 8) & 0xFF;
		$blue = $rgb & 0xFF;

	$cssrgb = "rgb(" . $red . "," . $green . "," . $blue . ")";

	echo '<div class="cutepixel h' . $x . 'v' . $y . '" style="position: relative; width: 100px; height: 100px; float: left; background-color: ' . $cssrgb . ';"></div>';

?>

That's pretty much all I want. I just need to stick it in a loop to find the value of each pixel and output the relevant HTML.
 
Last edited:
So does your PHP code work? I hope you're not going to be processing any large images as that will likely nuke the server with all that processing going on, not to mention the huge output file.
 
Back
Top Bottom