huoxin/auto-image-dimensions
Composer 安装命令:
composer require huoxin/auto-image-dimensions
包简介
Automatically fetches and applies width and height dimensions to Flarum image tags to prevent layout shift (CLS).
关键字:
README 文档
README
A Flarum extension that automatically fetches and applies width and height dimensions to all <img> tags in your forum posts.
By hardcoding the dimensions into the parsed XML of the posts, this extension eliminates Cumulative Layout Shift (CLS), dramatically improving your forum's page performance scores and scrolling experience.
Features
- Smart Processing: Uses highly optimized HTTP streams (via
FastImageSize) to only download the header bytes of remote images, drastically reducing memory and bandwidth overhead. - Dynamic Operating Modes: Choose how the extension extracts dimensions based on your server resources:
Client Mode (Default): Forum visitors automatically detect image dimensions in their browser and silently report them back to the server. Best for heavily cached or low-resource servers.Backend Mode: The server uses a background Queue Worker to fetch dimensions every time a post is created or edited.Hybrid Mode: Combines both approaches for maximum coverage.
- Data Integrity: Implements robust Optimistic Locking to ensure background workers never overwrite concurrent user edits.
- Network Proxy Support: Configurable proxy settings (e.g.
tcp://10.0.0.5:3128) for servers behind corporate firewalls. - Scheduled Backfills: Automatically retry failed image fetching on a daily, weekly, or monthly cron schedule.
Installation
Install with composer:
composer require huoxin/auto-image-dimensions:"*"
CLI Commands
If you have thousands of existing posts, you can manually trigger a backfill from the command line:
# Fetch dimensions for ALL images that don't have them php flarum image-dimensions:backfill # ONLY retry images that previously failed (e.g. due to 404s or timeouts) php flarum image-dimensions:backfill --retry-failed
Updating
composer update huoxin/auto-image-dimensions:"*"
php flarum migrate
php flarum cache:clear
Links
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-08