size reduction images

This commit is contained in:
Simon Martens
2025-09-29 23:30:34 +02:00
parent 269d635f1d
commit 9a856527cc
5 changed files with 96 additions and 66 deletions

View File

@@ -30,7 +30,8 @@ pictures/
### Performance Benefits
- **60-80% smaller file sizes** for layout browsing
- **Faster page loads** with compressed images
- **Additional 75% size reduction** from 50% resize for preview images
- **Faster page loads** with compressed and resized images
- **Full quality** maintained for detailed viewing
- **Progressive enhancement** with WebP support detection
@@ -47,12 +48,14 @@ Run the provided script to convert all existing images:
For individual files:
```bash
cwebp -q 75 -m 6 pictures/1771-42-166.jpg -o pictures/1771-42-166-preview.webp
# The script automatically calculates 50% dimensions
cwebp -q 75 -m 6 -resize 1200 800 pictures/1771-42-166.jpg -o pictures/1771-42-166-preview.webp
```
### Quality Settings
- **Quality**: 75% (good balance for text-heavy images)
- **Compression**: Level 6 (maximum compression)
- **Resize**: 50% (reduces file size by ~75% additionally)
- **Format**: WebP (excellent text preservation)
## Browser Support
@@ -72,11 +75,11 @@ cwebp -q 75 -m 6 pictures/1771-42-166.jpg -o pictures/1771-42-166-preview.webp
Typical compression results for newspaper images:
| Image Type | Original JPEG | WebP Preview | Savings |
|------------|---------------|--------------|---------|
| Text page | 800 KB | 320 KB | 60% |
| Mixed page | 1.2 MB | 480 KB | 60% |
| Image page | 1.5 MB | 750 KB | 50% |
| Image Type | Original JPEG | WebP Preview (50% + compression) | Total Savings |
|------------|---------------|----------------------------------|---------------|
| Text page | 800 KB | 80 KB | 90% |
| Mixed page | 1.2 MB | 120 KB | 90% |
| Image page | 1.5 MB | 190 KB | 87% |
## Development Notes

View File

@@ -2,6 +2,7 @@
# Script to generate high-quality WebP versions of original JPEG files
# These will be used for the single page viewer (enlarged view)
# Overwrites existing WebP files for fresh conversion
# Usage: ./scripts/generate_webp_originals.sh
# Colors for output
@@ -56,10 +57,9 @@ process_file() {
name_no_ext="${filename%.*}"
webp_file="$dir/${name_no_ext}.webp"
# Skip if WebP original already exists and is newer than source
if [ -f "$webp_file" ] && [ "$webp_file" -nt "$jpg_file" ]; then
echo -e "${YELLOW}Skipping $jpg_file (WebP exists and is newer)${NC}"
return 0
# Check if WebP original already exists
if [ -f "$webp_file" ]; then
echo -e "${YELLOW}Overriding existing WebP: $webp_file${NC}"
fi
# Convert to high-quality WebP

View File

@@ -1,6 +1,7 @@
#!/bin/bash
# Script to generate WebP preview images from existing JPEG files
# Resizes images to 50% and applies high compression for fast layout loading
# Usage: ./scripts/generate_webp_previews.sh
# Colors for output
@@ -23,6 +24,15 @@ if ! command -v cwebp &> /dev/null; then
exit 1
fi
# Check if ImageMagick identify is installed (for resizing)
if ! command -v identify &> /dev/null; then
echo -e "${YELLOW}Warning: ImageMagick identify not found. Resizing will be skipped.${NC}"
echo " Ubuntu/Debian: sudo apt-get install imagemagick"
echo " macOS: brew install imagemagick"
echo " CentOS/RHEL: sudo yum install ImageMagick"
echo ""
fi
# Check if pictures directory exists
if [ ! -d "$PICTURES_DIR" ]; then
echo -e "${RED}Error: Pictures directory '$PICTURES_DIR' not found${NC}"
@@ -32,6 +42,7 @@ fi
echo -e "${GREEN}Generating WebP preview images...${NC}"
echo "Quality: $QUALITY%"
echo "Compression: $COMPRESSION"
echo "Resize: 50% (for faster loading)"
echo ""
# Counters
@@ -54,16 +65,28 @@ process_file() {
name_no_ext="${filename%.*}"
webp_file="$dir/${name_no_ext}-preview.webp"
# Skip if WebP preview already exists and is newer than source
if [ -f "$webp_file" ] && [ "$webp_file" -nt "$jpg_file" ]; then
echo -e "${YELLOW}Skipping $jpg_file (preview exists and is newer)${NC}"
return 0
# Check if WebP preview already exists
if [ -f "$webp_file" ]; then
echo -e "${YELLOW}Overriding existing preview: $webp_file${NC}"
fi
# Get image dimensions and calculate 50%
dimensions=$(identify -ping -format "%w %h" "$jpg_file" 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$dimensions" ]; then
width=$(echo $dimensions | cut -d' ' -f1)
height=$(echo $dimensions | cut -d' ' -f2)
new_width=$((width / 2))
new_height=$((height / 2))
resize_params="-resize $new_width $new_height"
echo "Processing: $jpg_file -> $webp_file (${width}x${height}${new_width}x${new_height})"
else
# Fallback: no resizing if we can't get dimensions
resize_params=""
echo "Processing: $jpg_file -> $webp_file (no resize - couldn't get dimensions)"
fi
# Convert to WebP
echo "Processing: $jpg_file -> $webp_file"
if cwebp -q "$QUALITY" -m "$COMPRESSION" "$jpg_file" -o "$webp_file" 2>/dev/null; then
if cwebp -q "$QUALITY" -m "$COMPRESSION" $resize_params "$jpg_file" -o "$webp_file" 2>/dev/null; then
# Check file sizes
jpg_size=$(stat -f%z "$jpg_file" 2>/dev/null || stat -c%s "$jpg_file" 2>/dev/null)
webp_size=$(stat -f%z "$webp_file" 2>/dev/null || stat -c%s "$webp_file" 2>/dev/null)