Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting DPI for PNG files

Tags:

dpi

png

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.

like image 648
Paul Morrison Avatar asked Oct 11 '09 19:10

Paul Morrison


2 Answers

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
like image 126
RobS Avatar answered Sep 25 '22 05:09

RobS


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!

like image 32
Al. Avatar answered Sep 25 '22 05:09

Al.