title: How to determine which colour space to use in pdf to image conversion?
body: <p>I have a simple script that converts pdf files into png files.</p>
  
  <p>It essentially run this <code>convert</code> command:</p>
  
  <pre><code>convert -strip -quiet -quality 100 -alpha off -density 165% -scene 1 -colorspace sRGB "/data/input.pdf" "/output/image.png"
  </code></pre>
  
  <p>However I have this one particular pdf file which has a white background like this:</p>
  
  <p><a href="https://i.stack.imgur.com/gXmW1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gXmW1.jpg" alt="enter image description here"></a></p>
  
  <p>and the outcome looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/zVKBv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zVKBv.jpg" alt="enter image description here"></a></p>
  
  <p>You can see the white background has turned into black.</p>
  
  <p>I can fix it by simply switching the parameter to <code>-colorspace cmyk</code></p>
  
  <p>I ran <code>identify</code> on the file but it does not indicate <code>cmyk</code></p>
  
  <pre><code>&gt; identify /data/input.pdf
  /data/input.pdf PDF 1920x1080 1920x1080+0+0 16-bit sRGB 2.07246MiB 0.000u 0:00.000
  </code></pre>
  
  <p><strong>My question is:</strong></p>
  
  <p>How do I know when to use sRGB space (which works until this file comes along) and when to use cmyk?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The file <a href="https://drive.google.com/open?id=0BzMTD_LNX0z_cl9lN2pVbzI5SWc" rel="nofollow noreferrer">can be viewed here</a></p>
  
  <p>ImageMagick version information</p>
  
  <pre><code>&gt; convert --version
  Version: ImageMagick 6.9.9-19 Q16 x86_64 2017-10-24 http://www.imagemagick.org
  Copyright: © 1999-2017 ImageMagick Studio LLC
  License: http://www.imagemagick.org/script/license.php
  Features: Cipher DPC OpenMP 
  Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png tiff wmf x xml zlib
  </code></pre>
  
  <p>Here is the dockerfile that replicates my dev environment:</p>
  
  <pre><code>FROM ubuntu:16.04
  
  
  RUN apt-get update --fix-missing 
  RUN apt-get install -y libmagickwand-dev wget
  
  
  WORKDIR '/src'
  ENV IMAGEMAGICK_VERSION 6.9.9-19
  RUN wget --no-check-certificate https://github.com/ImageMagick/ImageMagick/archive/${IMAGEMAGICK_VERSION}.tar.gz -O ${IMAGEMAGICK_VERSION}.tar.gz &amp;&amp; \
      tar -zxvf ${IMAGEMAGICK_VERSION}.tar.gz &amp;&amp; \
      cd ImageMagick-${IMAGEMAGICK_VERSION} &amp;&amp; \
      ./configure &amp;&amp; \
      make &amp;&amp; \
      make install &amp;&amp; \
      ldconfig /usr/local/lib
  
  
  WORKDIR /
  COPY *.pdf /
  COPY *.sh /
  </code></pre>
  
  <p>Full set of files can be found here: <a href="https://github.com/kongakong/StackoverflowCode/tree/convert-pdf-imagemagic/imagemagick/46900660" rel="nofollow noreferrer">https://github.com/kongakong/StackoverflowCode/tree/convert-pdf-imagemagic/imagemagick/46900660</a></p>