2

I try to compress my ~1MB pngs to get a smaller image.

When I compress my images to jpeg with:

for i in card*.png ; do convert -resize 445x625 -background white -flatten "$i" ../medium/"${i%.*}.jpg" ; done

they end up about 100kb

So I tried

for i in card*.png ; do echo $i; convert -resize 445x625 "$i" ../medium/"${i%.*}.avif" ; done 

which results in avif images ~400kb, I guess because they are losslessly compressed.

How do I create lossy compressed avif images? And what would be a useful quality level to get images with the text still clearly readeable?

(I use ImageMagick 6.9.10-23 on Ubuntu)

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • I do not believe that avif is fully developed in ImageMagick. But you can try -density X, where X is between 0 and 100. The lower. the value, the more compressed. But that is just a guess, since avif is not even listed in the list of formats. Also it may only be implemented in testing in IM 7. You are using IM 6 – fmw42 Jan 17 '21 at 20:05
  • 1
    Sorry, I meant -quality X not -density X – fmw42 Jan 17 '21 at 20:44
  • 1
    -quality has no effect, when converting to aviff – rubo77 Jan 17 '21 at 22:23
  • Too bad. Sorry, but as I said it is still in development. – fmw42 Jan 17 '21 at 22:59

1 Answers1

1

libheif

You can install

apt install libheif-examples

and then use heif-enc to create heif files with:

for i in card*.png ; do echo $i; heif-enc "$i" -o "${i%.*}.avif" ; done

If you need avif format, you need to compile the latest version of libheif, which has the -A option to create avif files. (There is a section in the README there how to build it on your system. But at least on Ubuntu this is not leading to a running heif-enc)


Better use avifenc:

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
sudo apt install zsh # needed for this pspecific package install
brew install joedrago/repo/avifenc

Now you have the tool to create avif files with the syntax:

avifenc [options] input.[jpg|jpeg|png|y4m] output.avif

(use avifenc --speed 4 --min 20 --max 22 -j 8 to get a higher compression and use all 8 cores)

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • `avifenc` spits a 'segmentation fault' on Debian stable. Any ideas? – WGRM Aug 05 '21 at 02:13
  • I tried all. The only input and output. With and without -o as well as several found here and elsewhere. I guess it's just broken. I might compile the source or file a bug at the Debian maintainer. It's Debian. Most of times everything is good and then something is just broke. S* happens. – WGRM Aug 05 '21 at 04:07
  • Now it complains, that there is no codec... – WGRM Mar 18 '22 at 08:22
  • Don’t use this custom `avifenc` package because it’s outdated; instead use Homebrew’s official one: `brew install libavif`. – bfontaine Aug 25 '23 at 11:21