Jay Caines-Gooby

Back in 5 mins

Rendering bitmaps from PDFs at non-native sizes

Tuesday November 17, 2009 @ 04:32 PM (GMT)

Charanga’s primary instrumental teaching resources use a synchronised score and animated instrument to indicate which notes are played during the piece.

Each of the resources begins life as a Sibelius arrangement, from which we use both the midi and score output. We’ve got close to a thousand of these interactive pieces and with any job of this size, scriptable tools can really help speed up the production process.

Pete, our musical arranger, asked me if there was a quicker way for him to generate the PNGs needed by the interactive tool. Up to now he’d been exporting them directly from Sibelius.

Sibelius can batch export PDFs, so converting from these was definitely the way to go. The main problem with a straight imagemagick convert command, like:

  convert score.pdf score.png

is that the native size of the PDF probably isn’t the correct size for the PNG, and when you try and force the correct size with a resize:

  convert -resize 506x517 score.pdf score.png

You end up with a poor bitmapped image, because you might be scaling up from an effective smaller size; e.g. in my score example the native size of the PDF is only 271×276 and I’m trying to go to twice the size [506×517]. Hence the poor quality of the resulting PNG.

What’s required is to up the size of the PDF prior to the convert taking place; it is a vector format after all, so there’ll be no loss of quality with a larger image. A simple way to do this is to up the DPI of the PDF. ImageMagick will default to 72DPI unless told otherwise. Crank up the density (DPI) for a bigger image:

  convert -density 600 -resize 506x517 score.pdf score.png

And the resulting PNG is much more acceptible:

Comments

New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2011 Jay Caines-Gooby. All rights reserved.
Powered by Thoth.