Skip to main content

Bulk convert images to WebP and automatically update URLs in markdown files

Project description

bulk-webp-url-replacer

link

Bulk convert images to WebP and automatically update URLs in markdown files with a custom CDN prefix.

Features

  • 🔍 Extract image URLs from markdown files (frontmatter, galleries, inline images)
  • 📥 Download images from remote URLs (parallel downloads)
  • 🖼️ Convert to optimized WebP format
  • 🔄 Replace original URLs with new CDN-prefixed paths
  • ⏭️ Skip already-processed images and excluded extensions
  • 👀 Dry-run mode to preview changes

Installation

pip install bulk-webp-url-replacer

Or install from source:

git clone https://github.com/HoangYell/bulk-webp-url-replacer.git
cd bulk-webp-url-replacer
pip install -e .

Usage

CLI

# Dry run - preview what would be processed
bulk-webp-url-replacer \
  --scan-dir ./content \
  --output-dir ./webp_images \
  --dry-run

# Full run with custom URL prefix
bulk-webp-url-replacer \
  --scan-dir ./content \
  --output-dir ./webp_images \
  --new-url-prefix "https://cdn.example.com/images"

# Faster with more threads
bulk-webp-url-replacer \
  --scan-dir ./content \
  --output-dir ./webp_images \
  --new-url-prefix "https://cdn.example.com/images" \
  --threads 8

As Python Module

python -m bulk_webp_url_replacer \
  --scan-dir ./content \
  --output-dir ./webp_images \
  --new-url-prefix "https://cdn.example.com/images"

Options

Option Required Default Description
--scan-dir Yes - Directory to scan for files containing image URLs
--output-dir Yes - Directory to save converted WebP images
--new-url-prefix No - URL prefix to replace old image URLs
--quality No 80 WebP quality 1-100
--max-width No 1200 Max image width in pixels
--exclude-ext No gif svg webp ico File extensions to skip
--threads No 4 Number of parallel download threads
--dry-run No - Preview changes without downloading or modifying files

Supported Patterns

The tool detects image URLs in:

# YAML frontmatter
---
image: "https://example.com/image.jpg"
---

# TOML frontmatter
+++
image = "https://example.com/image.jpg"
+++

# Gallery shortcodes
{{< gallery >}}
- https://example.com/photo1.jpg
- https://example.com/photo2.png
{{< /gallery >}}

# HTML img tags in shortcodes
{{< embed >}}
<img src="https://example.com/image.jpg" width="250" height="250"/>
{{< /embed >}}

# Standard markdown
![Alt text](https://example.com/image.jpg)

Output

After running, you'll have:

  1. WebP images in your --output-dir
  2. mapping.json tracking original → WebP conversions
  3. Updated files with new URLs

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bulk_webp_url_replacer-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bulk_webp_url_replacer-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file bulk_webp_url_replacer-0.1.0.tar.gz.

File metadata

  • Download URL: bulk_webp_url_replacer-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for bulk_webp_url_replacer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 311f0e0c9e2e4e77000c419b47947359dc7a1af4a45085d41a37d41ae5af20dd
MD5 a9b6a602f5f01466f3d398cf956f16a0
BLAKE2b-256 8f16b6d37e84298bc95a72e32d7f4d8441e293e201c2ec45362777a0efc7f089

See more details on using hashes here.

File details

Details for the file bulk_webp_url_replacer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bulk_webp_url_replacer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd6f51c89f10182b07c977cfb0c4bd64a2f206f650a90f09967aff366ac705e
MD5 5416b2adbd14d37c00e0d3bef9972ba6
BLAKE2b-256 42c5cbb3b0d92431a0192493116c829f99f21029a1b0c81de76e72697a0945a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page