Page 2 of 2

Re: Counting Color and Grey Scale in a directory?

Posted: 2019-09-20T06:52:29-07:00
by ccameron
I was using this command - magick identify *.tif > report.csv. Just to identify all the files and images. It is working. The test file I was using was the problem.

Do you know of any way to identify gray scale and color images in a PDF?

Re: Counting Color and Grey Scale in a directory?

Posted: 2019-09-20T08:02:39-07:00
by snibgo
IM can read PDF images, via Ghostscript. So you could just use *.pdf in your command.

If you want to extract raster images from PDF files, use pdfimages.

Re: Counting Color and Grey Scale in a directory?

Posted: 2019-09-20T08:32:19-07:00
by bratpit
Just simple as previous.

Code: Select all

for i in *.pdf;do pdfimages -list "$i"|grep gray ;done|wc -l
for i in *.pdf;do pdfimages -list "$i"|grep rgb ;done|wc -l

Re: Counting Color and Grey Scale in a directory?

Posted: 2019-09-20T09:13:02-07:00
by ccameron
Ok, I installed Ghostscript and ran the magick identify *.pdf > report.txt. This is what the results look like.
1046.pdf[0] PDF 605x791 605x791+0+0 16-bit sRGB 13438B 0.016u 0:00.018
1046.pdf[1] PDF 605x791 605x791+0+0 16-bit sRGB 33097B 0.016u 0:00.017
1046.pdf[2] PDF 616x780 616x780+0+0 16-bit sRGB 785431B 0.016u 0:00.017

How do I determine if any of them are grey scale or color? I see RGB in them but I know there isn't color in it.

Re: Counting Color and Grey Scale in a directory?

Posted: 2019-09-20T10:01:45-07:00
by snibgo
The mere act of rasterizing a PDF doesn't calculate whether each page has any colour. You could:

Code: Select all

magick in.pdf -colorspace HCL -format %[fx:maxima.g]\n info:
This finds the maximum chroma of each page. When this is zero, the page is monochrome.