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


Derive Proc macro step by step

Thu 26 September 2024
Tokens stream in macro (photography) (Photo credit: wikipedia)

I recently try to write a proc_macro in rust but failed to find enough example and I didn't have all the needed knowledge to fully understand the examples I found.

The use case

Let's take a toy use case. Let's say we …

Category: howto Tagged: rust programming tutorial, howto

Read More

GNSS as an optimization problem

Thu 20 July 2023
Satellite optimized (Photo credit: Wikipedia)

GNSS's basic functionality works as follow: Satellites sends their position and their local time frequently. The time is synchronized between satellites thanks to the most accurate time keeping devices ever made (atomic clock). Each GNSS constellation implements its own time (e.g. GPS time). The …

Category: maths Tagged: python maths optimization

Read More

Suicide burn

Sat 27 August 2022
Rocket burn (Photo credit: Wikipedia)

Principle overview

The goal of the suicide burn (also called hoverslam) [1] is to land a rocket while minimal thrust is not low enough to hover [2]. Thus, the engine must be turned off at the point where the rocket land.

The challenge is then …

Category: aviation Tagged: aviation Fight dynamics rocket science

Read More

Differential thrust

Wed 27 July 2022
Differential thrust (Photo credit: GE)

Principle overview

The basic principle is to create a torque offsetting the total thrust. This offset is done by throttling thrust of multiple engines whose thrust is not align with gravity center.

On the drawing, the thrust is aligned with CG for the left engine …

Category: aviation Tagged: aviation Fight dynamics rocket science

Read More

Voting method reflections

Fri 28 January 2022
Transparent voting box (Photo credit: Wikipedia)

This article presents personal thoughts on voting methods. More specifically, it presents guarantees offer by the traditional non-electronic voting method and won’t elaborate on electronic voting.

Specifications

First, let’s define few specifications I’d like to develop.

  • any voter can understand how …

Category: reflections Tagged: geopolitics reflection vote

Read More
Page 1 of 12

Next »