jardim do jojo

Low Tech Images

// Publicado em: 28 de março de 2023

A picture from my cellphone has a resolution of 4032×3024 and size of 5.6MB. That is a lot of data to store and transmit over the Internet.

Can we do better?

Original picture:

$ magick identify original.jpg
original.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 5.32664MiB 0.000u 0:00.003

Resizing and keeping the aspect ratio. With a resolution of 1440x1080 we have 907KB. The quality difference is visible but acceptable.

$ convert original.jpg -resize 1080^ new.jpg
$ magick identify new.jpg 
new.jpg JPEG 1440x1080 1440x1080+0+0 8-bit sRGB 907010B 0.000u 0:00.001

With 960x720 we have 433KB, but the quality starts to bother me.

$ convert original.jpg -resize 720^ new.jpg
$ magick identify new.jpg
new.jpg JPEG 960x720 960x720+0+0 8-bit sRGB 433521B 0.000u 0:00.001

Another way to resize is using the scale option:

$ convert original.jpg -scale 50% new.jpg
$ magick identify new.jpg                       
new.jpg JPEG 2016x1512 2016x1512+0+0 8-bit sRGB 1.60792MiB 0.000u 0:00.000

The quality option specifies the image compression level and reduces quite a lot of space. A quality of 50 reduced the original image from 5.3MB to 1.3MB, affecting the result very little, IMHO.

$ convert original.jpg -quality 50 new.jpg      
$ magick identify new.jpg
new.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 1.39811MiB 0.000u 0:00.000

I like it, let’s keep.

Let’s also use -strip to remove the image metadata. We gain about 15KB.

$ convert original.jpg -scale 50% -quality 50 -strip new.jpg
$ magick identify new.jpg                                   
new.jpg JPEG 2016x1512 2016x1512+0+0 8-bit sRGB 438089B 0.010u 0:00.000

Magick Commands

# Get information from file
$ magick identify icon.ico

# Convert
$ magick image.svg result.png

# Convert and resize
$ magick image.svg -resize 64x64 result.png

# Make background transparent
# If doesn't work is probably because the SVG has no transparency channel
# Try doing in another software, like Inkscape
$ magick image.svg -background none -resize 64x64 result.png

# Create a multi resolution icon file form a png file
$ magick image.png -define icon:auto-resize="16,24,32,48,64" icon.ico 

# Resize with a scale
$ convert image.png -scale 25% result.png

Resources