Page 1 of 1

Understand if pdf is color or GrayScale

Posted: 2010-02-05T10:54:58-07:00
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.

Re: Understand if pdf is color or GrayScale

Posted: 2010-02-06T07:52:18-07:00
by myspacee
Anyone can help me please ?

m.

Re: Understand if pdf is color or GrayScale

Posted: 2010-02-06T10:39:48-07:00
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:

Re: Understand if pdf is color or GrayScale

Posted: 2010-02-10T10:19:42-07:00
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.

Re: Understand if pdf is color or GrayScale

Posted: 2010-02-10T11:11:55-07:00
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:...

Re: Understand if pdf is color or GrayScale

Posted: 2010-02-11T10:49:19-07:00
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.

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-09T17:55:36-07:00
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?

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-09T18:14:56-07:00
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

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-09T18:27:22-07:00
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.

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-09T19:38:01-07:00
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

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-12T02:05:13-07:00
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.

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-12T10:59:46-07:00
by snibgo
I suppose you have tried the obvious basic tests:

Code: Select all

ls anexArtigo.pdf
convert -identify anexArtigo.pdf

Re: Understand if pdf is color or GrayScale

Posted: 2010-03-14T23:59:35-07:00
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!!!