473,378 Members | 1,388 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,378 software developers and data experts.

determine if image is grayscale

tjh

hi -

i'm a bit new to PHP - i've been messing around with the GD2 image functions
and was wondering:

i see a lot of information about converting a color image to grayscale but i
can't figure out how to determine whether an image (GIF or JPG) is grayscale
in the first place.

is there a way to do this in PHP?

thanks for any advice!

tjh
Jul 17 '05 #1
3 3966
On Thu, 09 Sep 2004 17:24:43 GMT, "tjh" <t.******@ten.tsacmoc> wrote:
i'm a bit new to PHP - i've been messing around with the GD2 image functions
and was wondering:

i see a lot of information about converting a color image to grayscale but i
can't figure out how to determine whether an image (GIF or JPG) is grayscale
in the first place.

is there a way to do this in PHP?


If it's a paletted image, imagecolorsforindex(), or for a true colour image
loop through the pixels and usage imagecolorat().

All the colours should have their red, green and blue components equal, or
near equal, if it's a greyscale image.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Andy Hassall wrote:
On Thu, 09 Sep 2004 17:24:43 GMT, "tjh" <t.******@ten.tsacmoc> wrote:
i'm a bit new to PHP - i've been messing around with the GD2 image
functions and was wondering:

i see a lot of information about converting a color image to
grayscale but i can't figure out how to determine whether an image
(GIF or JPG) is grayscale in the first place.

is there a way to do this in PHP?


If it's a paletted image, imagecolorsforindex(), or for a true colour
image loop through the pixels and usage imagecolorat().

All the colours should have their red, green and blue components
equal, or near equal, if it's a greyscale image.


Looping throught all pixels may become tediously sllloooooowwww for bigger
pix. Why bother, just grayscale them regardless of previous state. Is that
an option for you ?
Pjotr
Jul 17 '05 #3
"tjh" <t.******@ten.tsacmoc> wrote in message
news:vl00d.163154$mD.122719@attbi_s02...

hi -

i'm a bit new to PHP - i've been messing around with the GD2 image functions and was wondering:

i see a lot of information about converting a color image to grayscale but i can't figure out how to determine whether an image (GIF or JPG) is grayscale in the first place.

is there a way to do this in PHP?

thanks for any advice!

tjh


For JPEG, you can call getimagesize() to get the number of color channels.
If it's one, then the image is greyscale. For GIF, you can scan the palette.
Jul 17 '05 #4

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

Similar topics

3
by: Defcon31 | last post by:
hello i receive from a dll a pointer to raw image data (307200bytes grayscale values). can someone explain how i can put this image data in a picturebox in VB? or can someone post code to do it...
0
by: Java script Dude | last post by:
In trying to speed up my web pages, I want to avoid using multiple images (disabled, hover, nohover). I've currently got opacity working on hover and it looks great and works in IE and Moz. But I...
6
by: QuasiChameleon | last post by:
Hi, I'm trying to create a grayscale image class that reads and writes grayscale Targa format. This works well with smaller images, but corrupts larger images and creates a "Segmentation fault...
0
by: udir | last post by:
Hi all, I have a ToolBar on my form. Each button associated to an image from an ImageList. Why when I disable the button, the button becomes all gray ( and not grayscale image ) ? Do I...
7
by: bcutting | last post by:
I am looking for a way to take a large number of images and find matches among them. These images may not be exact replicas. Images may have been resized, cropped, faded, color corrected, etc. ...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
49
by: comp.lang.php | last post by:
/** * Class for grayscaling image * * @author Phil Powell * @version 1.2.1 * @package IMAGE_CATALOG::IMAGE */ class ImageGrayscaleGenerator extends ImageResizeComponents { /
12
by: Speed | last post by:
Hi, Could you please tell me what is the simplest code to read a 8-bit grayscale JPEG using C++? Thanks a ton, Speed.
1
by: oruccim | last post by:
hi I want understanding pictures colorfull for examle colorfull or black-white image.google.com there are understand it .Can I understand it thanks....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.