Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Is there a way to determine type of image mode (rgb/indexed/greyscale)

Tue Nov 29, 2011 4:17 pm

I have a script that relies on an image being in indexed color mode at onset, switches to rgb (so the image can be scaled w interpolation) and then switches back to indexed.
If I use the script on an image that is in RGB mode it chokes and dies.
Is there a way to determine what mode an image is in so that I can handle these images accordingly?
Or is there a way to override the error message such that the rest of the script will execute?
Or maybe I'm going about doing this all wrong as it is and you know of a better way.

Thanks in advance.

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Tue Nov 29, 2011 4:47 pm

If you are authoring the script, you could just convert the image to the correct mode (if already that mode, it won't matter) in the script. Now I have to add, I'm not a script writer so don't ask me how. If you are like me, an end user, you can always check to see by doing Image>Mode to see. :)

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Tue Nov 29, 2011 5:00 pm

gimp-image-base-type will tell you what type of image you have, but if you want to only be able to run the script on a particular image type, then you should specify the type when registering it: http://docs.gimp.org/en/gimp-using-scri ... cript.html

That said, I think Lylejk's suggestion to set the image type to what you need it to be is a good one.

gimp-image-convert-indexed and gimp-image-convert-rgb would help here.

Note: I found all of these functions using the Procedure Browser:- Help >> Procedure Browser

Kevin

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Tue Nov 29, 2011 5:09 pm

gimp-image-base-type

Opps :oops: :ninja

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Tue Nov 29, 2011 5:15 pm

paynekj wrote:gimp-image-base-type will tell you what type of image you have, but if you want to only be able to run the script on a particular image type, then you should specify the type when registering it: http://docs.gimp.org/en/gimp-using-scri ... cript.html


That is what I was looking for! I kept searching in the PDB using the wrong words so never found this function. Thanks.

I wanted an automated way to handle the file type. So Lylejk's suggestion wasn't exactly what I was looking for.

Thanks for everyone's input!

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Wed Nov 30, 2011 10:17 am

FYI - when you register a script, the 7th parameter is type of image you want it to work on...

If you leave it blank "" it works with any kind.

If you only want users to call the script on indexed images, set it to "INDEXED" and it will be greyed out in the menu if the image is RGB greyscale.

Other options are RGB, RGBA, RGB*, GRAY, GRAYA, GRAY* which you can use for any combination:
"RGB GRAY* INDEXED" would enable the menu items for image/layers RGB (without alpha), greyscale (alpha or not) or indexed.

-Rob A>

Re: Is there a way to determine type of image mode (rgb/indexed/greysc

Wed Nov 30, 2011 10:52 am

RobA wrote:FYI - when you register a script, the 7th parameter is type of image you want it to work on...

If you leave it blank "" it works with any kind.

To clarify, if you leave it blank then it works on any kind of image or no image at all -- for example, if you are writing a script that generates a new image from scratch and does not care whether an image is already open.

To specify that an image must be open -- but without caring what kind of image -- use "*" for the constraint parameter.
Post a reply