1

I have an image Image.png. How do I use the ImageMagick command convert to make this file into a Image.jpg file with the following requirements:

  1. File size is 200~500 kb.
  2. Resolution in not less than 450 dpi
  3. Image size 35 x 45 mm

Edit: These are the exact requirements for making some documents through electronic government. IT isn't a problem that the quality will deteriorate, because the image is needed just for the process of making the document (not for the document itself).

I'm not entirely clear in understanding what these requirements mean with respect to a file. I figured out how to get .jpg from .png:

$ convert Image.png Image.jpg

Also, I found out how to set some specific DPI:

$ convert -units PixelsPerInch Image.png -density 450 Image.jpg

However, I'm not sure about millimeters, and how it's determined in an image file.

5
  • 1
    Please add details to your question about which arguments to hte imagemagick command you have tried and how they didn't work.
    – verdammelt
    Jan 17, 2014 at 22:01
  • @verdammelt - Thank you. I added some details now.
    – Loom
    Jan 18, 2014 at 0:01
  • I'm going to guess that these are for passport photos of some sort? Am I right? persofoto.com/lexicon/passport-photo/size
    – slm
    Jan 18, 2014 at 3:37
  • @slm - Thank you for corrections. This photo that I want to convert will for internal use of government office only. Passport photo itself they will make when I visit the office.
    – Loom
    Jan 18, 2014 at 9:51
  • Passport photos can be made through makepassportphoto.com/en/p/photo-for-united-states-passport
    – pauljeba
    Sep 18, 2020 at 16:17

2 Answers 2

4

The command

convert Image.png  -resize 620x797 -quality 1 Image.jpg

meets your claims. However PNG is lossless compression and JPG is lossy, so you can compress as much as you want, but the result may not meet your needs.

How to figure it out:
450 dot per inch means 450 pixel per 25.4 mm
to get the width: 450*35/25.4 = 620
to get the height: 450*45/25.4 = 797

0
2

Just convert DPI to metric: 450 DPI equals 17.71 dots per mm.

This gives you 17.71 * 35 = 621 pixels (you have to round up) or more for the width and 17.71 * 45 = 798 pixels or more for the height.

With that use normal convert resize:

convert Image.png -resize 621x798 Image.jpg

to get the size right.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .