Converting images

14 May 2024

While JPG and PNG were once the most dominant image file formats, there are now lots of new options including AVIF and WebP. ThemeIsle did a comparison of AVIF and WebP. Their conclusion was that AVIF is better for compression without side-effects, but WebP is more widely adopted.

In this article I'll touch on how I work with the different files.

Converting DNG files

DNG files are a bit harder to work with. On Ubuntu I use darktable to convert them to JPG-files with their CLI tool.
darktable-cli inputfile.dng outputfile.jpg
Simple as that. Even keeps the EXIF data.
find . -type f \( -iname "*.dng" \) -exec sh -c 'darktable-cli {} ${0%.*}.jpg' {} \; -delete

How I work with AVIF files

https://web.dev/compress-images-avif/ https://stackoverflow.com/questions/65765174/convert-png-images-to-lossy-avif

Converting AVIF to PNG

pip3 install pillow-avif-plugin
from PIL import Image
import pillow_avif

img = Image.open('input.avif')
img.save('output.png')

Converting PNG to AVIF

convert image.png image.avif

How I work with WebP files

Converting to WebP

cwebp input.jpg -o output.webp

Converting from WebP to PNG

dwebp input.webp -o output.png

You might also enjoy

Privacy policy

Privacy policy

Published 2024-07-28

Privacy/data policy for the website PhilipSoerensen.com

Read the post →
Get started developing Wordpress plugins in 5 minutes

Get started developing Wordpress plugins in 5 minutes

Published 2024-05-14

Developing plugins for Wordpress can be easy. Start developing customized code for Wordpress today.

Read the post →
How I use Slack as a logging tool

How I use Slack as a logging tool

Published 2024-04-26

You can use Slack to send messages to yourself from your websites. Here I explain how I can send Slack messages from my own website.

Read the post →