473,546 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3974
On Thu, 09 Sep 2004 17:24:43 GMT, "tjh" <t.******@ten.t sacmoc> 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, imagecolorsfori ndex(), 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.andyhsoftwa re.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.t sacmoc> 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, imagecolorsfori ndex(), 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.t sacmoc> wrote in message
news:vl00d.1631 54$mD.122719@at tbi_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
6415
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 please ??? thanks in advance
0
6866
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 now need a grayscale filter to show the image as disabled. Does anybody know of a Mozilla way of doing this. I know that -moz-opacity works for...
6
3297
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 (core dumped)" error. I am at a loss as to why this works only part of the time. I hope it's proper etiquette to post the code below (3 files). ...
0
1385
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 have to apply a second grayscale image for each button for disable mode ?
7
13527
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. Approach 1 Programmatically extract the information (such as Eigen Vectors/Eigen Spaces) and store them in a database. Then apply a comparison...
8
47858
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 that image in grayscale format.How do i do that.It still saves in true color format. -i used picturebox1.image.save() method -i tried to convert...
49
1691
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
5110
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
1936
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....
0
7507
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...
0
7435
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...
0
7698
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. ...
0
7947
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...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5361
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...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
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

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.