9

I have a bunch of diagrams created using a Java diagramming tool that I wrote - they are mostly black and white diagrams, with the blocks in aqua, and occasional other colours. They are currently being saved as JPG files, and I want to insert them into a book that I am preparing for Print On Demand.

The book is an OpenOffice ODT file, which will later be converted to a PDF.

Currently I use JPG files, but the print facility they use requires 300 DPI, so I modified my diagramming tool to set the xDensity and yDensity to 300, and resUnits to 1, using getAsTree(), and then expand the diagram by a factor of 3 (300/96). IMO the result looks pretty good!

Unfortunately, someone on another forum pointed out that line diagrams are "fuzzed" on JPG files, so suggested that I change over to PNG, or possibly BMP files, both of which ODT files allow to be inserted.

My problem is that BMPs don't seem to have a DPI, and PNGMetadata doesn't seem to support getAsTree(). Can someone point me in the right direction? Thanks.

3 Answers 3

23

I don't understand the getAsTree() part, but answering the question that appears in the title, setting dpi for PNG files, you could use the imagemagick convert tool:

convert -density 300 -units pixelsperinch infile.jpg outfile.png
3
  • I just meant that I wanted to set the DPI programmatically... but I've changed my mind! So imagemagick sounds interesting - thanks! Oct 13, 2009 at 13:46
  • It appears that when providing a PNG as input, the alpha channel is lost. Feb 13, 2013 at 12:57
  • 1
    Either "-alpha Set" or "-alpha On" may help here. But the documentation (imagemagick.org/script/command-line-options.php) is a little confusing and I don't have any alpha-channel pngs to hand to test.
    – RobS
    Feb 13, 2013 at 13:38
3

PNG, BMP and dozens of other image formats don't compress your diagrams - compression is probably what your commentor was getting at. JPEGs are great for photos but suck at diagrams.

You might want to look into SVG and other vector formats. Or if your environment allows, exporting 0% compression JPEGs and converting them into another format for lossless reproduction at 300DPI.

Hope that helps!

2
  • +1. It seems to me that this question is about vector vs. raster images. And the OP should surely use vectors for self-created diagrams.
    – Sparhawk
    Nov 16, 2013 at 3:02
  • 2
    PNG certainly does compress your images. It is just a lossless compression as opposed to JPEG's lossy compression.
    – Matt
    Oct 26, 2016 at 17:26
0

I decided not to try to do this programmatically. Instead I create the original diagram in PNG, then convert to 300 DPI using Irfanview. Irfanview's batch capability lets me convert to 300 DPI, scale up to compensate, and set to grey scale, all in one operation - and on multiple files at a time. This seems to be the best solution - but thanks to everyone anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.