How to match colors with GIMP when converting PDF?

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
theweakestlink
Posts: 5
Joined: 2019-05-21T13:36:54-07:00
Authentication code: 1152

How to match colors with GIMP when converting PDF?

Post by theweakestlink » 2019-05-21T14:10:58-07:00

First off, I'm a relative newcomer to ImageMagick. I'm attempting to script a process that I've been doing by hand using GIMP, however the colors I'm getting from IM are very different. I need to figure out how to match the colors so that things continue to be the same for our customer's experience.

Code: Select all

Version: ImageMagick 7.0.8-45 Q16 x64 2019-05-13 http://www.imagemagick.org
My input files in this case are CMYK PDFs produced with InDesign. Here is a snippet from 'magick identify -verbose' on a typical file:

Code: Select all

  Properties:
    date:create: 2019-05-21T16:08:39+00:00
    date:modify: 2019-05-21T16:08:39+00:00
    dc:format: application/pdf
    illustrator:StartupProfile: Print
    illustrator:Type: Document
    pdf:HiResBoundingBox: 612x792+0+0
    pdf:Producer: Adobe PDF Library 15.0
    pdf:Trapped: False
    pdf:Version: PDF-1.4
    photoshop:ColorMode: 3
    photoshop:ICCProfile: sRGB IEC61966-2.1
    signature: 48264b748a183f9485306b8c1ab0c02039df8ef97f7a9a5cfeb9c20ea9e3fa6a
    tiff:XResolution: 720000/10000
    tiff:YResolution: 720000/10000
    xmp:ColorSpace: 1
    xmp:CreateDate: 2019-05-20T14:20:31-04:00
    xmp:CreatorTool: Adobe InDesign 14.0 (Macintosh)
    xmp:MetadataDate: 2019-05-20T14:20:32-04:00
    xmp:ModifyDate: 2019-05-20T14:20:32-04:00
    xmp:PixelXDimension: 187
    xmp:PixelYDimension: 187
    xmpMM:DerivedFrom: default
    xmpMM:DocumentID: xmp.id:5b5e3b18-1c50-4b3a-b53f-b0f35190e00c
    xmpMM:InstanceID: uuid:39a6a229-af2f-dd42-ae37-c9fef2179146
    xmpMM:OriginalDocumentID: xmp.did:42204DDF1620681197A584965A8A0009
    xmpMM:RenditionClass: proof:pdf
    xmpTPg:HasVisibleOverprint: False
    xmpTPg:HasVisibleTransparency: False
    xmpTPg:MaxPageSize: Millimeters
    xmpTPg:NPages: 1
  Profiles:
    Profile-xmp: 2472 bytes
My current process is: Import first page into GIMP, setting density to 120 px; auto-crop empty margins; scale to 300 px tall; export as PNG. This results in a PNG with 8-bit depth in the sRGB colorspace.

The script I have written so far (using Windows PowerShell) produces this command line:

Code: Select all

magick convert -verbose -density 120 "C:\Users\Me\Documents\Test.pdf[0]" -background white -alpha remove -trim -resize 410x300 -profile "C:\Users\Me\Documents\Color Profiles\sRGB_v4_ICC_preference.icc" -colorspace sRGB -depth 8 "C:\Users\Me\Documents\Test.png"
Result:

Code: Select all

[ghostscript library 9.26] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGri dFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r120x120" -dUseCIEColor -dFirstPage=1 -dLastPage =1 "-sOutputFile=C:/Users/Me/AppData/Local/Temp/magick-2160h3OuOvoTD6HI%d" "-fC:/Users/Me/AppData/Local/Temp/magick- 2160AXAVJjkhUay-" "-fC:/Users/Me/AppData/Local/Temp/magick-2160ZpftXs8EVJDU"C:/Users/Me/AppData/Local/Temp/magick-21 60h3OuOvoTD6HI1 PAM 1020x1320 1020x1320+0+0 8-bit ColorSeparation CMYK 5.13621MiB 0.031u 0:00.021

C:\Users\Me\Documents\Test.pdf[0]=>C:\Users\Me\Documents\Test.pdf PDF 1020 x1320 1020x1320+0+0 16-bit ColorSeparation CMYK 5.13621MiB 0.063u 0:00.067

C:\Users\Me\Documents\Color Profiles\sRGB_v4_ICC_preference.icc ICC 1x1 1x1+0+0 16-bit sRGB 60960B 0.016u 0:00.001 writing raw profile: type=xmp, length=2472

C:\Users\Me\Documents\Test.pdf[0]=>C:\Users\Me\Documents\Test.png PDF 1020 x1320=>225x300 255x330+15+15 8-bit sRGB 5.13621MiB 0.266u 0:00.113
I am using GhostScript 9.26 instead of 9.27 because 9.27 refused to produce any output for me; I read about a bug related to PDF conversion so I downgraded.

The profile I had downloaded from ICC just today, to see if it made a difference. So far as I can tell, there is no difference between the output quality now and that of my initial tests where I didn't specify a profile at all. I had been hoping that if I could get GIMP and ImageMagick to use the same color profiles it might help.

Unfortunately, I am not permitted to share these files, and I am not sure how to create a suitable test image myself.

If anyone could help me figure out what I'm missing here, I would greatly appreciate it! :D
Last edited by theweakestlink on 2019-05-21T14:55:06-07:00, edited 1 time in total.

snibgo
Posts: 11683
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to match colors with GIMP when converting PDF?

Post by snibgo » 2019-05-21T14:22:56-07:00

You use IM v7, so I suggest you use "magick" and "magick identify" instead of "convert" and "identify".

Remove "-colorspace sRGB". As your input has a profile, I suggest you use "-profile" if you need to, not "-colorspace".

Your "identify -verbose" says the file has a sRGB profile, but the text from your output says it is a CMYK file. So something is wrong.
snibgo's IM pages: im.snibgo.com

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

Re: How to match colors with GIMP when converting PDF?

Post by fmw42 » 2019-05-21T14:32:58-07:00

My current process is: Import first page into GIMP, setting density to 120 px
I presume that means 120 dpi, not 120 pixels.

theweakestlink
Posts: 5
Joined: 2019-05-21T13:36:54-07:00
Authentication code: 1152

Re: How to match colors with GIMP when converting PDF?

Post by theweakestlink » 2019-05-21T14:54:15-07:00

snibgo wrote:
2019-05-21T14:22:56-07:00
You use IM v7, so I suggest you use "magick" and "magick identify" instead of "convert" and "identify".

Remove "-colorspace sRGB". As your input has a profile, I suggest you use "-profile" if you need to, not "-colorspace".

Your "identify -verbose" says the file has a sRGB profile, but the text from your output says it is a CMYK file. So something is wrong.
Thanks for the fast reply! Sorry, the full command I'm using is "magick convert ..." I will edit my post for clarity.

As for the "identify" mismatch, are you referring to the "photoshop:" tag? If so, I think that refers to an embedded raster image on the page; similarly, there's a tag from Illustrator, but the PDF itself was output from InDesign. I didn't want to post the entire verbose output, as it's 256 lines, but at the top there is:

Code: Select all

Image: .\Test.pdf
  Base filename: Test.pdf
  Format: PDF (Portable Document Format)
  Mime type: application/pdf
  Class: DirectClass
  Geometry: 612x792+0+0
  Resolution: 72x72
  Print size: 8.5x11
  Units: PixelsPerInch
  Colorspace: CMYK
  Type: ColorSeparation
  Endianess: Undefined
  Depth: 16/8-bit
  ...
I have removed the colorspace parameter from my command, but the output remains the same. Specifically, everything is more bright and skewed toward dayglo/neon colors when it should be more subtle. :|

@fmw42, you are correct. :)

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

Re: How to match colors with GIMP when converting PDF?

Post by fmw42 » 2019-05-21T15:09:50-07:00

Do not use magick convert. Use simply magick in IM 7. If you use magick convert it may give you IM 6 results. The other tools such as identify and mogrify, etc do need to be prefaced by magick.

theweakestlink
Posts: 5
Joined: 2019-05-21T13:36:54-07:00
Authentication code: 1152

Re: How to match colors with GIMP when converting PDF?

Post by theweakestlink » 2019-05-21T16:55:39-07:00

OK, thanks again. New command line:

Code: Select all

magick -verbose -density 120 "C:\Users\Me\Documents\Test.pdf[0]" -background white -alpha remove -trim -resize 410x300 -profile "C:\Users\Me\Documents\Color Profiles\sRGB_v4_ICC_preference.icc" -depth 8 "C:\Users\Me\Documents\Test.png"
Verbose output:

Code: Select all

[ghostscript library 9.26] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGri dFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r120x120" -dUseCIEColor -dFirstPage=1 -dLastPage =1 "-sOutputFile=C:/Users/Me/AppData/Local/Temp/magick-11656aIpNdEI6aXQR%d" "-fC:/Users/Me/AppData/Local/Temp/magick -11656Mj4_Bn88Lwjm" "-fC:/Users/Me/AppData/Local/Temp/magick-11656OcTxWqTr7bGa"C:/Users/Me/AppData/Local/Temp/magick -11656aIpNdEI6aXQR1 PAM 1020x1320 1020x1320+0+0 8-bit ColorSeparation CMYK 5.13621MiB 0.016u 0:00.017

C:\Users\Me\Documents\Test.pdf[0]=>C:\Users\Me\Documents\Test.pdf PDF 1020 x1320 1020x1320+0+0 16-bit ColorSeparation CMYK 5.13621MiB 0.063u 0:00.070

C:\Users\Me\Documents\Color Profiles\sRGB_v4_ICC_preference.icc ICC 1x1 1x1+0+0 16-bit sRGB 60960B 0.000u 0:00.001

C:\Users\Me\Documents\Test.pdf[0]=>C:\Users\Me\Documents\Test.png PDF 1020 x1320=>225x300 255x330+15+15 8-bit CMYK 5.13621MiB 0.188u 0:00.087
Color output remains the same, as far as I can see. Here, I think I can share a small sliver of each so you can actually see what I'm talking about!

Good: Image Bad: Image

Would it help for me to post the entire verbose "identify" data for the "good" and "bad" images? I've been reluctant to do that because of length.
Last edited by theweakestlink on 2019-05-21T17:21:04-07:00, edited 1 time in total.

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

Re: How to match colors with GIMP when converting PDF?

Post by fmw42 » 2019-05-21T17:07:21-07:00

This forum does not support image uploads. You will need to post to some free hosting service and put the URLs here.

Imagemagick offloads work to convert PDFs to Ghostscript which cannot deal with multiple colorspaces in the PDF, nor if you have an imbedded image with a different colorspace to the vector PDF shell. So if you have imbedded images, you would be better of extracting the image from the vector PDF shell using pdfimages tool.

theweakestlink
Posts: 5
Joined: 2019-05-21T13:36:54-07:00
Authentication code: 1152

Re: How to match colors with GIMP when converting PDF?

Post by theweakestlink » 2019-05-21T17:33:21-07:00

Ah, I see. That does make sense. I understand how GhostScript might have difficulty with this collection of random stuff.

I will look at using the "pdftopng" tool from xpdf-utils, as that looks to be exactly what I need and is probably easier than learning how to automate GIMP. ;)

I never know what I'm going to find in customer PDFs, so it's important to use the right tool for the job.

snibgo
Posts: 11683
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to match colors with GIMP when converting PDF?

Post by snibgo » 2019-05-21T17:36:24-07:00

theweakestlink wrote:Would it help for me to post the entire verbose "identify" data for the "good" and "bad" images?
That might help, with the commands that made both images. I notice that neither of your snips have embedded ICC profiles.
snibgo's IM pages: im.snibgo.com

theweakestlink
Posts: 5
Joined: 2019-05-21T13:36:54-07:00
Authentication code: 1152

Re: How to match colors with GIMP when converting PDF?

Post by theweakestlink » 2019-05-22T14:05:09-07:00

@snibgo, that's probably because I did the snips with GIMP; it doesn't seem to write profile data into PNGs, at least for me. :)

Just to bring some closure to this, I did manage to get a working solution by using pdftopng to grab the first page and produce a PNG, which is then fed to ImageMagick for trimming and resizing. It was a few more hoops than I thought I'd have to jump through, but now I have a better framework for handling other image types.

In case anyone is interested, the resulting color is 99% the same as with GIMP, which in my book is close enough. There is a minor difference in text clarity, but for the intended purpose it doesn't matter.

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

Re: How to match colors with GIMP when converting PDF?

Post by fmw42 » 2019-05-22T14:39:52-07:00

If you are starting with PDF, perhaps your pdftopng tool will permit you to set a larger rendering density. Then you can resize down to the original size. I do that all the time with ImageMagick. I set the density 4x default of 72 = 288, then after rendering, I resize down by 1/4 = 25%

Code: Select all

convert -density 288 image.pdf -resize 25% image.png
That gives a pretty clear result for text.

Post Reply