Convert image with imagemagick command line convert tool

10,918

Solution 1

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

Solution 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.

Share:
10,918

Related videos on Youtube

Loom
Author by

Loom

Updated on September 18, 2022

Comments

  • Loom
    Loom over 1 year

    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.

    • verdammelt
      verdammelt over 10 years
      Please add details to your question about which arguments to hte imagemagick command you have tried and how they didn't work.
    • Loom
      Loom over 10 years
      @verdammelt - Thank you. I added some details now.
    • slm
      slm over 10 years
      I'm going to guess that these are for passport photos of some sort? Am I right? persofoto.com/lexicon/passport-photo/size
    • Loom
      Loom over 10 years
      @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.
    • pauljeba
      pauljeba over 3 years