Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Batch Resize Images on Linux Using Mogrify (ImageMagick)

Batch Resize Images on Linux Using Mogrify (ImageMagick)

4

One problem I encountered recently was saving space on the web server which was being used to store user-uploaded photos. The current upload directory was approaching 8 GB in size – the limit for the Ubuntu Amazon AIM. So I had to find a quick solution to compressing the images (some of which had resolutions of 5 megapixels and higher).

I found that using mogrify (which somes with ImageMagick) was a quick and easy solution to resizing the images. I first had to Install ImageMagick on the server:

Then, I was ready get compressing. I wanted to resize all images larger than 1024 x 1014 pixels to that size.

The command explained:

  1. Resizes images larger than 1024×1024 to 1024×1024, while keeping the correct aspect ratio.
  2. Resize all images to 1024×1024. Images larger than this size will be scaled down, while smaller images will be scaled up.
  3. Resize all images with the ‘jpg’ extension

The -verbose flag will explain how the image was resized, giving the before and after dimensions.

mogrify can also be used for other manipulation operations, like converting a JPEG image to PNG. Typing in the commend without any flags will give you other operations you can perform, or you can read more about it here.

CLI, Command Line, Linux, Server

4 comments on “Batch Resize Images on Linux Using Mogrify (ImageMagick)”

  1. Iván Yossi says:
    April 13, 2013 at 12:56 AM

    Could you share the command?

    Reply
  2. Iván Yossi says:
    April 13, 2013 at 1:00 AM

    Oh i see them now. the didn’t appear the first time

    Might be a good idea to add a resampler filter to keep quality

    Reply
  3. ssk2 says:
    May 28, 2013 at 1:39 PM

    Why does ‘mogrify’ need to be run as sudo? Seems like bad practice to me.

    Reply
    • Niraj Shah says:
      May 28, 2013 at 3:44 PM

      It doesn’t need to be. It may be required depending on file permissions (since in my case, the files were uploaded by the www-data user, and I was logged in as another).

      Reply

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

PSN Profile

Tags

Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache API Application Backup Bug Command Line Cordova Example Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Flash Geolocation Google Nexus 5 Google Nexus One Hacking HTML5 Image Manipulation iOS iPhone JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2022 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy