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:
- Resizes images larger than 1024×1024 to 1024×1024, while keeping the correct aspect ratio.
- Resize all images to 1024×1024. Images larger than this size will be scaled down, while smaller images will be scaled up.
- 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.
Could you share the command?
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
Why does ‘mogrify’ need to be run as sudo? Seems like bad practice to me.
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).