Batch resising for web

Sun 05 October 2025
Smaller environment (Photo credit: wikipedia)

I recently tried to measure the environmental impact of this website. I used an online tool. The result shows the easiest way to improve my score was to reduce image sizes. This could easily be done with ImageMagick.

I wrote a small bach script to resize my files:

#!/bin/bash

# resize images for web use

target_size=200 # in kb
output_dir="web"
mkdir -p $output_dir

resize_image() {
    echo "image $1..."
    output_file=$output_dir/$1
    cp "$1" "$output_file"
    current_size=$(( $(stat -c%s "$output_file") / 1024 ))
    factor=95
    while (( current_size > target_size ))
    do
        echo "current size: $current_size"
        current_size=$(( $(stat -c%s "$output_file") / 1024 ))
        magick "$1" -resize $factor% "$output_file"
        factor=$(( factor - 5 ))
    done
}

for image in *jpg
do
    resize_image "$image"
done

It tries several resize factor (while loop, factor being redefined line 20) until the output size is lower than a predefined threshold.

Then, I needed to replace path in all my articles.

Category: how to Tagged: bash jpg magick web blog how to


Back online

Mon 18 February 2019

I've migrated the blog from wordpress to pelican. Static files, quite easy to use.

The migration process went well. The pelican import tool is easy to use and my rst linter highlighted the few errors done by the import tools (mainly empty sections).

There are still few artefacts due to …

Category: tools Tagged: pelican wordpress blog tools

Read More

happy birthday

Fri 19 September 2014

[caption id="" align="alignright" width="350"]English: Birthday candle, Downpatrick, County ... Birthday candle (Photo credit: Wikipedia)[/caption]

One year ago,  I begun this blog. The first post was about what I expected from the blog. Lets look backward. This blog contains:

  • about 60 posts published
  • almost all are posts in english
  • few posts are in …

Category: blog Tagged: Assessment Birthday Blog

Read More
Page 1 of 1