473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1914
On Thu, 30 Aug 2007 15:20:12 +0200, William Gill <no*****@exampl e.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 = imagecreatefrom jpeg("/your/image/file");

$pixels = array();
for($x = 0; $x < imagesx($im); $x++){
for($y = 0; $y < imagesy($im);$y ++){
$rgb = imagecolorat($i m, $x, $y);
//either:
$pixels[$x][$y] = imagecolorsfori ndex($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 = imagecreatefrom jpeg("/your/image/file");

$pixels = array();
for($x = 0; $x < imagesx($im); $x++){
for($y = 0; $y < imagesy($im);$y ++){
$rgb = imagecolorat($i m, $x, $y);
//either:
$pixels[$x][$y] = imagecolorsfori ndex($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*****@exampl e.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
2666
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: $FileDest = "/uploads/1.gif"; if (!move_uploaded_file($_FILES, $FileDest)):
15
2210
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 email in newsgroup postings, but then, I'm postmaster and welcome spam :) TIA -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek
0
3781
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 and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
7
777
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)? When I try to open the image the usual way, e.g.: Image img = Image.FromFile("thefilename.tif"), I get an error ("not enough memory"). This meaningful error message always comes up when .NET cannot deal with the Image format I think... Thanks,
16
11875
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. I can do this individually for each graph but this does not help me as I need both on the same JPEG. I thought I would try an export the form that contains both but I am having trouble. (My VBA is self taught and a little knowledge is...
0
2222
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 help me... I've scoured all the documentation, google, and mailing lists to no avail. I believe the problem may lay in a jpeglib problem with OSX 10.3.9, or a python paths problem.
1
7828
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 compression ratio is.. thanks!
2
6303
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 SAME EXACT file from the same location using Internet Explorer it registers as a image/pjpeg. My understanding is that IE translates it to a progressive jpeg and FF doesn't care. Any speacial reason why? Can I avoid this in the script so it treats...
1
3244
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. I have the contents of a Jpeg loaded into an Image object, _Image, using the Image.FromFile method. I convert the Text property of a TextBox to a byte array with code
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.