0

I prefer to backup ~/Documents to a tar file and move that tar file to a removable solid state drive. After many years of collecting data, my tar file is approximately 4 GB which is nice since I can collect about 3 of these on a 16 GB USB flash drive with room to spare.

Sometimes I create photos of monochrome documents or scans of those documents. These images seem to end up hard to predict sizes depending on what my phone camera or scanner does. If they are less than 1 MB they acceptable. If they are 2 MB or more than I get annoyed because these are a long term inconvenience for my tar backup process. I hope that my tar file never gets as large as 5 GB. Sometimes I run gimp to make the images smaller.

I have noticed that a 3 MB image file can be gimp cropped and exported at 40% to 50% quality and they can end up at 200 kb to 500 kB and the text is still legible. Gimp import, crop, export at 50%, and visually check legibility is too tedious and manual. It would be easier to just do a lossy compression. If I can do lossy compression on a bunch of images easily that would be even more convenient.

The default easy compression process on Ubuntu 20.04 is to select several images, right click, and pick a format from radio buttons labelled...

.zip

.tar.xz

.7z

This document says .xz is dangerous long term so I don't want that format. .zip and .7z do not seem to reduce the size much.

What is already installed by default on Ubuntu that is a lossy photo (or multiple photo) compression that is easy to use and convenient? Convenience implies GUI is preferred but it's not an absolute requirement but it would be a pain to have to type many file names or rename files to make wildcards work. Speed of compression and uncompression is not important since I will seldom access these files.

2 Answers 2

0

The answer is ImagemMagick on both counts. It's practically on every system under the sun, and especially the convert utility.

1
  • To be more verbose imagemagick offers the convert utility. convert intputfile -quality 10% outputfile For JPG files small quality arguments do not seem to reduce the file size more than somewhat larger arguments so perhaps 20% is not any smaller than 60%. I also decided to install jpegoptim and run it after the convert. jpegoptim --size=50% filename.
    – H2ONaCl
    Jan 10, 2023 at 6:53
0

I decided to use both convert (from imagemagick) and also jpegoptim.

Examples...

convert inputfile -quality 50% outputfile

jpegoptim --size=50% targetfile

As a script...

#!/bin/bash

filenameending='.jpg'
modifier='_shrunk'

convertcommand='convert'
qualitystring='-quality %50'

jpegoptimcommand='jpegoptim'
sizestring='--size=50%'

for filename in *$filenameending ; do
  du -hk $filename
  # example... convert inputfile -quality 50% outputfile
  filenameroot="${filename%.jpg}"
  outputfilename="$filenameroot$modifier$filenameending"
  commandstring="$convertcommand $filename $qualitystring $outputfilename"
  echo $commandstring
  eval $commandstring
  # rm $filename
  du -hk $outputfilename
  # example... jpegoptim --size=50% targetfile
  commandstring="$jpegoptimcommand $sizestring $outputfilename"
  echo $commandstring
  eval $commandstring
  du -hk $outputfilename
  echo ' '
done
exit 0

Neither imagemagick nor jpegoptim are default applications on Ubuntu 20.04 so this solution is less convenient that requested in the question posting, however, both tools seem easy to use and can be conveniently installed with sudo apt get.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .