How to change DPI of a PNG file? (in command line, without ImageMagick)

dpipng

I am looking for a way to change the DPI on PNG image files. Using ImageMagick this is easy:

$ convert -density 150 -units pixelsperinch file.png file.png

The problem is that I will run this command from my application, running on multiple VMs, which don't have ImageMagick installed. I can push the upgrade packages to these VMs, but in case of ImageMagick that would add about 30MB to an upgrade bundle, which is a bit too much for my use case.

Long story short: is there a way I can change the DPI on a PNG file using a small (as in package size) command-line tool?

Optionally, changing bytes in a raw image file would be okay too, if someone knows where to look for them…

Best Answer

Is 2.10 MB small enough? If yes, use NConvert and a batch command like:

nconvert -out png -dpi 150 -keepdocsize -keepfiledate mysource.png

What is NConvert for?

XnView is a GUI-based application, you can change and manipulate images using a graphical user interface. NConvert has about the same capabilities as XnView, but it is a command line tool and has no graphical user interface. You can use NConvert in Batch scripts or another application can call it.

Helpful links

  • Beginner guide and Wiki with some examples to start
  • Help file to see what command line parameters are available (Uploaded on pastebin)
  • A graphical front-end using Nconvert is XnConvert. Use this to create & export Nconvert batch files
  • Forum for Xnconvert and Nconvert for
Related Question