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


Cache implementation using weakref

Fri 30 April 2021
Bird's cache (Photo credit: Wikipedia)

This article presents a quick example of how to use weakref to implement a home-made cache mechanism.

Let's use the following use case:

  • Let's consider items:
    • items can be stored on a storage
    • items can be retrieved from storage
    • items are identify by an ID …

Category: how to Tagged: python cache weakref

Read More

Tkinter and Asyncio

Thu 18 February 2021
Asynchronous process results waiting (Photo credit: Wikipedia)

Graphical interfaces are typically the kind of object that can take advantage of asynchrounous programming as a GUI spend lot of time waiting for user input.

Tkinter <https://docs.python.org/3/library/tkinter.html#module-tkinter>_ is a kind of standard for …

Category: how to Tagged: python asyncio

Read More

Travis setup

Tue 12 May 2020
One job in continuous integration pipeline (Photo credit: Wikipedia)

The goal is to setup a CI pipeline based on Travis with external dependencies integrated to a Github repository

Travis basics

To enable Travis integration in Github, one must edit ./.travis.yml file.

I won't go into detail. The setup is …

Category: how to Tagged: travis ci how to

Read More

Wikidata crawling

Sun 26 April 2020
Graph database representation (Photo credit: Wikipedia)

I wish to have reliable data about vehicles. I decided to rely on one large source, namely Wikipedia. I chose it because it is reviewable and most of the time reviewed, and regularly updated and completed.

Wikipedia - Wikidata relationship

Wikidata items are made to …

Category: how to Tagged: python wikipedia wikidata html

Read More
Page 1 of 3

Next »