473,414 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

jpeg image decompiling

I have found a couple of sites that allow a visitor to upload an image
and the site returns either the "average color", or a palette of colors.
Several of them use PHP to accomplish this. I have requested the source
code, but have not gotten a response (even though one site states
"source code available on request"). It is obvious that they read the
colors of each pixel and them manipulate that data. I would like to be
able to do something similar.

I'm not very familiar with the PHP image functions, but have been able
to figure out how to read pixel color on indexed color images, but not
on jpegs. The best I can do now is convert a jpeg to a 256 indexed
color image, and then read pixel color. Unfortunately too much of the
original data gets lost.

Does anyone know how to determine the color of jpeg pixels, or can you
point me to a good tutorial on PHP image functions.

For what it's worth, one of the things I want to do is determine the
distribution of each color (i.e. 345 pixels of rgb1, 2436 pixels of
rgb2, etc.), and possibly manipulate the image by removing and/or
replacing any given color.


Aug 30 '07 #1
6 1899
On Thu, 30 Aug 2007 15:20:12 +0200, William Gill <no*****@example.invalid
wrote:
I have found a couple of sites that allow a visitor to upload an image
and the site returns either the "average color", or a palette of colors.
Several of them use PHP to accomplish this. I have requested the source
code, but have not gotten a response (even though one site states
"source code available on request"). It is obvious that they read the
colors of each pixel and them manipulate that data. I would like to be
able to do something similar.

I'm not very familiar with the PHP image functions, but have been able
to figure out how to read pixel color on indexed color images, but not
on jpegs. The best I can do now is convert a jpeg to a 256 indexed
color image, and then read pixel color. Unfortunately too much of the
original data gets lost.

Does anyone know how to determine the color of jpeg pixels, or can you
point me to a good tutorial on PHP image functions.
<http://nl3.php.net/imagecolorat>

$im = imagecreatefromjpeg("/your/image/file");

$pixels = array();
for($x = 0; $x < imagesx($im); $x++){
for($y = 0; $y < imagesy($im);$y++){
$rgb = imagecolorat($im, $x, $y);
//either:
$pixels[$x][$y] = imagecolorsforindex($im,$rgb);
//or:
$r = ($rgb >16) & 0xFF;
$g = ($rgb >8) & 0xFF;
$b = $rgb & 0xFF;
$pixels[$x][$y] = array($r,$g,$b);
}
}

--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.
Aug 30 '07 #2
>
<http://nl3.php.net/imagecolorat>

$im = imagecreatefromjpeg("/your/image/file");

$pixels = array();
for($x = 0; $x < imagesx($im); $x++){
for($y = 0; $y < imagesy($im);$y++){
$rgb = imagecolorat($im, $x, $y);
//either:
$pixels[$x][$y] = imagecolorsforindex($im,$rgb);
//or:
$r = ($rgb >16) & 0xFF;
$g = ($rgb >8) & 0xFF;
$b = $rgb & 0xFF;
$pixels[$x][$y] = array($r,$g,$b);
}
}
Thanks, Rik.

I played with imagecolorat() before, but it didn't seem to work with a
non indexed color image (i.e. it worked with a gif, but not a jpeg).
Reading the spec seemed to confirm that the function returns the color
index (not the color), which can then be read for rgb values. I was
able to convert the jpeg to an indexed image, then use imagecolorat(),
but it meant reducing the original to 256 colors first.

I will try again, using your snippet, and let you know.
Aug 30 '07 #3


William Gill wrote:
>>
<http://nl3.php.net/imagecolorat>

I played with imagecolorat() before, but it didn't seem to work with a
non indexed color image (i.e. it worked with a gif, but not a jpeg).
Reading the spec seemed to confirm that the function returns the color
index (not the color), which can then be read for rgb values. I was
able to convert the jpeg to an indexed image, then use imagecolorat(),
but it meant reducing the original to 256 colors first.

I will try again, using your snippet, and let you know.
further digging says on PHP with GD >= 2.0, imagecolorat() should return
rgb on truecolor images. I need to do some more digging and testing.
Aug 30 '07 #4
On Thu, 30 Aug 2007 17:59:18 +0200, William Gill <no*****@example.invalid
wrote:
>

William Gill wrote:
>>>
<http://nl3.php.net/imagecolorat>
I played with imagecolorat() before, but it didn't seem to work witha
non indexed color image (i.e. it worked with a gif, but not a jpeg).
Reading the spec seemed to confirm that the function returns the color
index (not the color), which can then be read for rgb values. I was
able to convert the jpeg to an indexed image, then use imagecolorat(),
but it meant reducing the original to 256 colors first.
I will try again, using your snippet, and let you know.
further digging says on PHP with GD >= 2.0, imagecolorat() should return
rgb on truecolor images. I need to do some more digging and testing.
Indeed. Use print_r(gd_info()); to see the specifics of your gd version.

--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.
Aug 30 '07 #5
Indeed. Use print_r(gd_info()); to see the specifics of your gd version.
v 2.0.34, and I am getting rgb info now. I must have done something
wrong before.

Thanks again!
Aug 30 '07 #6
William Gill wrote:
I have found a couple of sites that allow a visitor to upload an image
and the site returns either the "average color", or a palette of colors.
Several of them use PHP to accomplish this. I have requested the source
code, but have not gotten a response (even though one site states
"source code available on request"). It is obvious that they read the
colors of each pixel and them manipulate that data. I would like to be
able to do something similar.

I'm not very familiar with the PHP image functions, but have been able
to figure out how to read pixel color on indexed color images, but not
on jpegs. The best I can do now is convert a jpeg to a 256 indexed
color image, and then read pixel color. Unfortunately too much of the
original data gets lost.

Does anyone know how to determine the color of jpeg pixels, or can you
point me to a good tutorial on PHP image functions.

For what it's worth, one of the things I want to do is determine the
distribution of each color (i.e. 345 pixels of rgb1, 2436 pixels of
rgb2, etc.), and possibly manipulate the image by removing and/or
replacing any given color.

You really don't 'need' PHP for this... take a look at imagemagick at

http://www.imagemagick.org

and

http://www.imagemagick.org/Usage/compare/#metrics

Norm
Aug 31 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ming | last post by:
Hi All, I want to write a PHP webpage which allows people to upload images (no matter what formats) to me and at the same time converts any non-jpeg image to JPEG. Here's what I have: ...
15
by: Christos TZOTZIOY Georgiou | last post by:
Has anyone built PIL (1.1.4 or 1.1.5) for Python 2.4? If yes, please let me know, since I can't test a couple of my apps using PIL with 2.4 . You can even reply by email (yes, I dare use true...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
7
by: Albert Greinöcker | last post by:
hi ng, I have a question concerning image processing in .NET: How can I open a jpeg with a tiff-header in c# (which means the file has the extension .tif, but contains jpeg-compressed data)?...
16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
0
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please...
1
by: Smokey Grindel | last post by:
I have a bitmap object I want to return as a JPEG image with a compression set at 90% and progressive passes enabled, how can I do this in .NET 2.0? Progressive passes are not necessary but the...
2
by: David Lozzi | last post by:
Howdy, I have a simple file uploader in a form, and I take the image and check for the file extension. Now I when upload a jpg image in FireFox the content type is image/jpeg. When I upload the...
1
by: Joe Cool | last post by:
I am attempting to add a function to an application I am working on to modify the JPEG Comment in a Jpeg image file. I can retrieve the JPEG Comment with no problem. The problem is modifying it....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.