PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Sep 20, 2019 2:06 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon Jun 04, 2007 3:46 am 
Offline
Forum Newbie

Joined: Mon Jun 04, 2007 3:41 am
Posts: 4
Hi all,

This is my first message here.

I would like to know how many channels an image has.

The image may be a BMP, JPEG, PNG, or any number of other formats (but these are the most common).
The image might also have an ALPHA channel.
The image might be compressed (like in PNG - you can decide how compressed you want the image to be).

At first I used the "getimagesize" function to retreive the number of channels,
but I realised :
1. It some times returns 0.
2. In images with an ALPHA channel - it doesn't count that channel.

Does anyone here have a solution for me please ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:25 am 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135
I'm not quite sure what you're trying to accomplish. Different types of images work very differently and should be handled as such. Maybe could help.

And maybe you should read up on more of the functions and different ways to handle different files with the .


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:35 am 
Offline
Forum Newbie

Joined: Mon Jun 04, 2007 3:41 am
Posts: 4
All I want to do is know if the image has an ALPHA channel or not ...
Can anyone please please help me accomplish that ?
I've read dozens of threads about this already.
getimagesize seems to return 3 channels even when there is a 4th ALPHA channel present ...
And I've also gone over the GD library and could not find a cure there ...
please help someone


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 7:56 am 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135
can give you the color that is automatically given an alpha of 0 (mostly exists for gif images).

attempts to set a flag to save alpha information in an image... It may fail on images without the capability.

takes an RGB value and an alpha value, and gives you the index of a color that's almost like it. I assume that using an alpha of 0 would give you the closest color to being an alpha of 0 (unless RGB takes precedence... you should try it out.) I think that, in combination with should give you the closest color's alpha value. If it doesn't exist, it may be safe to assume that the image has no alpha values.

All of this is from the GD library... I know the fact that it has a lot of functions is intimidating, but the documentation is there so that when something needs to be done, you've got a place to find the tools in order to do it. It's no fun to read it, but you're bound to need it. :wink:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:07 am 
Offline
Forum Newbie

Joined: Mon Jun 04, 2007 3:41 am
Posts: 4
Hi,

I have tried what you have suggested with no luck.
Most of the functions you mentioned are SET functions, rather than GET functions ...

Any other solution ?

It's odd such a simple problem does not have a simple solution.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:14 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
You could just analyze the headers. It's not as difficult as you may think.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:15 am 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:17 am 
Offline
Forum Newbie

Joined: Mon Jun 04, 2007 3:41 am
Posts: 4


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 9:04 am 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135
Well, PNG files always have an alpha channel, but it's not always utilized.

GIF file might have one... .

JPEGs and BMPs don't.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 9:44 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 9:46 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 12:44 pm 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group