This question already has an answer here:

I have Ubuntu 10.04. I have converted image through terminal using the following command:

convert myfigure.png myfigure.jpg

But I want to resize the height and width of the converted image. Is there any way to do this?

marked as duplicate by Charles Green, pa4080, Wild Man, karel, Yaron Sep 12 '17 at 6:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 168 down vote accepted

Same command, with an extra option:

convert myfigure.png -resize 200x100 myfigure.jpg

or

convert -resize 50% myfigure.png myfigure.jpg

To resize multiple files, you can try the following command (as suggested by @test30)

find . -maxdepth 1 -iname "*.jpg" | xargs -L1 -I{} convert -resize 30% "{}" _resized/"{}"
  • 6
    You can also use percentage, as in convert -resize 50% myfigure.png myfigure.jpg – January Mar 24 '13 at 9:48
  • @January excellent :) – Rinzwind Mar 24 '13 at 9:56
  • If I want to convert all images in a folder what's the best command then? does convert -resize 50% *.JPG work? tnx – Ehsan M. Kermani Sep 7 '14 at 19:30
  • 3
    resize all images in current dir by 50% find -maxdepth 1 . -iname "*.jpg" | xargs -l -i convert -resize 50% {} /tmp/{} src: perturb.org/display/632_ImageMagick_resize_images.html I added maxdepth :) – test30 Dec 10 '14 at 21:57
  • 3
    Found that to do all the pictures the . needed to be before -maxdepth so it should be this: find . -maxdepth 1 -iname "*.JPG" | xargs -l -i convert -resize 25% {} email/{} – Andrew Stern Jul 9 '15 at 22:58

If you want CLI only:

sudo apt-get install imagemagick
mogrify -resize 320x240 Image.png 
mogrify -resize 50% Image.png
mogrify -resize 320x240 *.jpg

If you wanna try GUI:

Install nautilus-image-converter

sudo apt-get install nautilus-image-converter

It adds two context menu items in nautlius so you can right click and choose "Resize Image".(The other is "Rotate Image").

You can do a whole directory of images in one go if you like and you don't even have to open up an application to do so.

  • Is there any more capable CLI software than this? It crashes and works on approx 80% images. – Luka Mar 29 at 19:24

Since Ubuntu ships with Python, you can also use a Python script to achieve this with a little more control over what happens - see this stackoverflow question for example scripts. Those examples use just the standard library.

Script #1

import os, sys
import Image

size = 128, 128

for infile in sys.argv[1:]:
    outfile = os.path.splitext(infile)[0] + ".thumbnail"
    if infile != outfile:
        try:
            im = Image.open(infile)
            im.thumbnail(size, Image.ANTIALIAS)
            im.save(outfile, "JPEG")
        except IOError:
            print "cannot create thumbnail for '%s'" % infile

And another example where you only have to specify the width (as the width variable):

Script #2

from PIL import Image
import sys

filename = sys.argv[1:]
basewidth = 300
img = Image.open(filename)
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
img.save(filename) 

Now, how to do this through the terminal...

sudo nano resizescript.py

Paste one of those blocks of code into the text editor. Ctrl+x to exit (say yes to save changes).

To use Script #1:

python resizescript.py yourfilenamehere.jpg

To use Script #2:

python resizescript.py yourfilenamehere.jpg

You must be in the same directory as the picture files for both of these scripts. The first one shrinks the image to 128x128 pixels. The second script makes it 300 pixels wide and calculates the proportional height. This is more of a Python answer, but it is done all through the terminal technically.

  • please include example(s) here – Zanna Sep 10 '17 at 20:20
  • Please provide the example through the terminal as per question. – kenorb Sep 10 '17 at 21:10
  • Thanks, I assumed too much in my first answer. I have made the edits per question. – freeworld Sep 12 '17 at 0:05
  • Note that PIL is only available for Python 2; support for 3.x is planned "later" as per pythonware.com/products/pil – arp Jan 21 at 16:13
  • For Python 3 there's Pillow - that's a fork of PIL. Confusingly enough it's in Debian repositories under python3-pil package. Aside from that, it's available via pip3 package manager. – Sergiy Kolodyazhnyy Dec 2 at 9:32

imgp is a relatively new utility that does image resize and rotation. It has more features than nautilus-image-converter.

  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Kevin Bowen Oct 5 '16 at 6:21

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