Tango
Tango

Reputation: 678

ImageMagick: Transparent Backgrounds for JPEG, not PNG

I'm using ImageMagick to convert PDF files to PNGs. (Lots of text, so I'd rather use PNG over JPEG.) I'm doing this on OS X, 10.8.2.

I tried using Ghostscript, then ImageMagick, as was done here and I got a gray background. I shortened it to one line, since ImageMagick can work with PDFs and tried this:

 convert -background transparent -transparent white \
          Background-Page01.pdf TestClearX1.png

I've tried that with PNG files and JPEG files. (And with and without -transparent white as well.)

If it's a JPEG, I can get a white background (which is probably clear, but in my viewer, I can't tell), but with a PNG, I always get a dark background. I thought about, as a test, trying to generate a BMP, then converting that to PNG, but it won't generate BMP files.

How can I get a transparent background for a PNG file?

And if that's not possible, since JPEG files are not good for text, is there a better alternative?

Upvotes: 1

Views: 884

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207808

This isn't an answer, but the format of the comment section doesn't allow sensible formatting, so I am offering it here instead.

You alluded to the fact that Preview in OS X doesn't show transparency properly, and that is correct. To get around that, I made the following script, which overlays the files you want to view onto a checkerboard pattern like Photoshop does. I save it as preview and then use chmod +x preview on it to make it executable. Here is the script:

#!/bin/bash
################################################################################
# preview
# Preview images using OSX "open" but overlay images on top of checkerboard 
# first so you can see transparency/transparent pixels, since Preview renders
# them grey :-(
################################################################################
for f in "$@"
do
   base=$(basename "$f")
   composite -compose Dst_Over -tile pattern:checkerboard "$f" "/tmp/$base"
   open -g "/tmp/$base"
done

That enables you to do:

/.preview file1.png file2.gif

and the -g option also means Preview doesn't steal focus too :-)

So, instead of looking like this:

enter image description here

it looks like this:

enter image description here

Upvotes: 2

Matt
Matt

Reputation: 3687

There's two ways to export a PDF in LibreOffice, and one way does not provide any warnings. The other way provides a warning that PDF/A cannot have transparent objects. The problem is you're using PDF/A files that don't support transparent objects—this results in your PNG always having a background colour.

Upvotes: 1

Related Questions