title: How to crop transparent (or even white) PNG?
body: <p>I would like to automatically crop a <code>foo.png</code> with either white or transparent background and ran into the warning (and actually error for transparent background) "mogrify: profile 'icc': 'RGB ':  RGB color space not permitted on grayscale PNG `foo.png' @ warning/png.c/MagickPNGWarningHandler/1656."</p>
  
  <p><code>foo.png</code> is created in <code>R</code> via </p>
  
  <pre><code>x &lt;- 1:10
  y &lt;- rev(x)
  png(file=(file &lt;- "crop.png"), bg="transparent")
  plot(x, y, xlab="x", ylab="y")
  dev.off()
  </code></pre>
  
  <p>If I then use either <code>mogrify -trim foo.png</code> or <code>convert foo.png -trim +repage foo_cropped.png</code>, I receive the above warning and the file is only cropped vertically, not horizontally (which should actually be viewed as an error). If I use <code>bg="white"</code>, then it is cropped on all sides but I still obtain the above warning. How can this be avoided? Ideally, I'm looking for a command line tool available in Linux and on the Mac which is able to crop <code>.png</code> files. </p>