Understand if pdf is color or GrayScale

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Understand if pdf is color or GrayScale

Post by myspacee »

Hello to all,
is there any way to understand if a pdf/image is color or GrayScale ?

link 2 production pdf :

http://www.webalice.it/t.bavaro/PA3POH.pdf
http://www.webalice.it/t.bavaro/PA5POH.pdf


I see that histogram can return different info :
convert PA3POH.pdf -format %c -depth 8 histogram:info:-

Code: Select all

...       
       453: (249,249,249) #F9F9F9 rgb(249,249,249)
       160: (250,250,250) #FAFAFA grey98
       145: (251,251,251) #FBFBFB rgb(251,251,251)
        88: (252,252,252) #FCFCFC grey99
        53: (253,253,253) #FDFDFD rgb(253,253,253)
        34: (254,254,254) #FEFEFE rgb(254,254,254)
    739286: (255,255,255) #FFFFFF white

convert pa5poh.pdf -format %c -depth 8 histogram:info:-

Code: Select all

...       
       221: (253,253,253,  0) #FDFDFD00 cmyk(253,253,253,0)
       187: (254,254,254,  0) #FEFEFE00 cmyk(254,254,254,0)
       156: (255,178,116,  0) #FFB27400 cmyk(255,178,116,0)
         6: (255,211,169,  0) #FFD3A900 cmyk(255,211,169,0)
     15854: (255,255,255,  0) #FFFFFF00 white

PA3POH.pdf -> RGB ?
pa5poh.pdf -> CMYK ?

If this can help me to understand if color or grayscale, how to extract only this info ? (RGB or CMYK)


thank you for your time,

m.
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Understand if pdf is color or GrayScale

Post by myspacee »

Anyone can help me please ?

m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Understand if pdf is color or GrayScale

Post by fmw42 »

try this, if returns 1=grayscale, if returns 0=color

convert image.pdf -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:

or

convert image.pdf miff:- | convert - -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Understand if pdf is color or GrayScale

Post by myspacee »

thank you for reply,
try to run both command to both files and obtain :

Code: Select all

convert PA3POH.pdf -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]

Code: Select all

cconvert PA5POH.pdf -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]
-----------------------------------------------------

Code: Select all

convert PA3POH.pdf miff:-   | convert - -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]

Code: Select all

convert PA5POH.pdf miff:-   | convert - -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]
Using windows seven and last IM, anyone can solve this riddle?

Thank you,

m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Understand if pdf is color or GrayScale

Post by fmw42 »

myspacee wrote:thank you for reply,
try to run both command to both files and obtain :

Code: Select all

convert PA3POH.pdf -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]

Code: Select all

cconvert PA5POH.pdf -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]
-----------------------------------------------------

Code: Select all

convert PA3POH.pdf miff:-   | convert - -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]

Code: Select all

convert PA5POH.pdf miff:-   | convert - -scale 1x1! -format "u.r==u.g&&u.r==u.b?1:0]" info:
u.r==u.g&&u.r==u.b?1:0]
Using windows seven and last IM, anyone can solve this riddle?

Thank you,

m.

You did not copy what I wrote. Should be

"%[fx:u.r==u.g&&u.r==u.b?1:0]"


you missed the %[fx:...
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Understand if pdf is color or GrayScale

Post by myspacee »

I'm a noob, now i know. :)

Add a % (now doubled) to string, to use in batch mode for Windows environment... It works!

Code: Select all

cconvert PA3POH.pdf -scale 1x1! -format "%%[fx:u.r==u.g&&u.r==u.b?1:0]" info:
cconvert PA5POH.pdf miff:- | cconvert - -scale 1x1! -format "%%[fx:u.r==u.g&&u.r==u.b?1:0]" info:
Thank you,

m.
plgx

Re: Understand if pdf is color or GrayScale

Post by plgx »

fmw42 wrote:try this, if returns 1=grayscale, if returns 0=color

convert image.pdf -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:

or

convert image.pdf miff:- | convert - -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:

I tried them on the Terminal.app of my MacBookPro running OS X 10.6.2, but returned nothing (I just got the prompt again).
Did I miss something? Should I echo something instead of info?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Understand if pdf is color or GrayScale

Post by fmw42 »

I tried them on the Terminal.app of my MacBookPro running OS X 10.6.2, but returned nothing (I just got the prompt again).
Did I miss something? Should I echo something instead of info?
Do you have IM installed?

convert -version

Does that return anything?

Did you substitute your pdf filename for image.pdf?

cd to directory where you have your images located, then try my command with your filename instead of image.pdf
plgx

Re: Understand if pdf is color or GrayScale

Post by plgx »

fmw42 wrote: Do you have IM installed?
Yes
fmw42 wrote:convert -version

Does that return anything?
It returns:
Version: ImageMagick 6.2.8 06/11/08 Q16 http://www.imagemagick.org
fmw42 wrote:Did you substitute your pdf filename for image.pdf?

cd to directory where you have your images located, then try my command with your filename instead of image.pdf
That's what I did. I've tried it again. In fact, after cding into the directory I wrote
"convert myfile.pdf "
and then pasted the rest of your command (that is the part after where it says "convert image.pdf "
and got nothing. No '1', no '0', just the bash prompt.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Understand if pdf is color or GrayScale

Post by fmw42 »

The problem is likely that your IM version 6.2.8-x is too old. You are over 300 versions behind. IM is currently at 6.6.0-4. You will need to upgrade, I suspect.

Do you have Ghostscript installed? I cannot remember whether you need it to convert to or from PDF

convert -list configure

look for the line

DELEGATES or perhaps CONFIGURE. Does it include gs?

Mine says

DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr openexr png tiff x11 xml zlib

or

convert -list format

and see if you get rw+ for PDF

PDF PDF rw+ Portable Document Format
plgx

Re: Understand if pdf is color or GrayScale

Post by plgx »

Sorry for the delay.
fmw42 wrote:The problem is likely that your IM version 6.2.8-x is too old. You are over 300 versions behind. IM is currently at 6.6.0-4. You will need to upgrade, I suspect.
I hadn't realized that the version of fink that I had on my computer was from before I had moved to SnowLeopard. It wasn't really working as it should've anyway. As soon as I deleted my fink directory, ImageMagick 6.5.2-0, that I had in my system, started working. It's still old, though not as much.
fmw42 wrote: Do you have Ghostscript installed? I cannot remember whether you need it to convert to or from PDF

convert -list configure

look for the line

DELEGATES or perhaps CONFIGURE. Does it include gs?

Mine says

DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr openexr png tiff x11 xml zlib

or

convert -list format

and see if you get rw+ for PDF

PDF PDF rw+ Portable Document Format
I do have ghostscript (v. 8.70) but I get
DELEGATES bzlib jpeg jng jp2 png tiff zlib
although I do get
PDF rw+ Portable Document Format

So it still doesn't work. I get the following message:

mbpgilberto:dibArtigo copy g$ convert anexArtigo.pdf -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:
convert: unable to open image `anexArtigo.pdf': No such file or directory @ blob.c/OpenBlob/2440.
convert: missing an image filename `info:' @ convert.c/ConvertImageCommand/2775.

mbpgilberto:dibArtigo copy g$ convert anexArtigo.pdf miff:- | convert - -scale 1x1! -format "%[fx:u.r==u.g&&u.r==u.b?1:0]" info:
convert: unable to open image `anexArtigo.pdf': No such file or directory @ blob.c/OpenBlob/2440.
convert: missing an image filename `miff:-' @ convert.c/ConvertImageCommand/2775.
convert: missing an image filename `info:' @ convert.c/ConvertImageCommand/2775.
mbpgilberto:dibArtigo copy g$



I'll upgrade tomorrow and let you know.
Last edited by plgx on 2010-03-16T23:41:58-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Understand if pdf is color or GrayScale

Post by snibgo »

I suppose you have tried the obvious basic tests:

Code: Select all

ls anexArtigo.pdf
convert -identify anexArtigo.pdf
snibgo's IM pages: im.snibgo.com
plgx

Re: Understand if pdf is color or GrayScale

Post by plgx »

Sorry.
I had't done the basic obvious tests for the last run. (It was a png, not a pdf file)
So your command worked marvelously (both on the png as on a pdf version of the file)!
Thanks!!!
Post Reply