mathiasgrimm/laravel-cloud-binaries
Composer 安装命令:
composer require mathiasgrimm/laravel-cloud-binaries
包简介
Pre-built static binaries for Laravel Cloud (jpegoptim, optipng, pngquant, cwebp, dwebp, avifenc, avifdec, gifsicle, ffmpeg, ffprobe, magick)
README 文档
README
Pre-built, statically compiled binaries for Linux (amd64/musl). Designed to be installed as a Composer package so that vendor/bin/ contains ready-to-use tools on Laravel Cloud (or any Linux environment).
This package includes all the binaries required by spatie/image-optimizer, making it a drop-in solution for image optimization on environments where system packages are not available. Note that svgo is not included as it is a regular npm package and can be installed via npm install -g svgo.
Binaries included
| Binary | Purpose |
|---|---|
jpegoptim |
JPEG optimization |
optipng |
PNG optimization |
pngquant |
PNG lossy compression |
cwebp |
WebP encoding |
dwebp |
WebP decoding |
avifenc |
AVIF encoding |
avifdec |
AVIF decoding |
gifsicle |
GIF optimization |
ffmpeg |
Audio/video transcoding |
ffprobe |
Media stream analysis |
magick |
ImageMagick 7 (replaces convert/identify/mogrify) |
All binaries are statically linked against musl libc (Alpine Linux). They will not run on macOS — this is expected.
Pinned versions
All upstream versions are defined at the top of the Makefile and passed to each Dockerfile via --build-arg. To bump a version, change the single variable in the Makefile.
| Binary | Variable | Current version | Size |
|---|---|---|---|
| jpegoptim | JPEGOPTIM_VERSION |
v1.5.6 |
1.0 MB |
| optipng | OPTIPNG_VERSION |
0.7.8 |
797 KB |
| pngquant | PNGQUANT_VERSION |
3.0.3 |
1.3 MB |
| cwebp | LIBWEBP_VERSION |
v1.5.0 |
1.6 MB |
| dwebp | LIBWEBP_VERSION |
v1.5.0 |
1.3 MB |
| avifenc | LIBAVIF_VERSION |
v1.2.1 |
7.8 MB |
| avifdec | LIBAVIF_VERSION |
v1.2.1 |
7.7 MB |
| gifsicle | GIFSICLE_VERSION |
v1.96 |
1.3 MB |
| ffmpeg | FFMPEG_VERSION |
n7.1.1 |
29 MB |
| ffprobe | FFMPEG_VERSION |
n7.1.1 |
29 MB |
| magick | IMAGEMAGICK_VERSION |
7.1.1-43 |
12 MB |
| Total | 93 MB |
Installation
composer require mathiasgrimm/laravel-cloud-binaries
Composer will symlink all 11 binaries into vendor/bin/.
Selective installation (faster deploys)
If you only need a few binaries, you can install the package as a dev dependency, copy just the ones you need into your repository, and avoid downloading the full ~93 MB on every deploy:
composer require --dev mathiasgrimm/laravel-cloud-binaries # Copy only the binaries you need into your project mkdir -p bin cp vendor/bin/jpegoptim bin/ cp vendor/bin/optipng bin/ cp vendor/bin/pngquant bin/ # Commit them git add bin/ git commit -m "Add image optimization binaries"
Then reference them from your application using base_path('bin/jpegoptim') (or whichever path you chose). Since the binaries are committed to your repository, they are available immediately during deployment with no Composer overhead.
To keep your committed binaries in sync automatically when the package is updated, add a post-update-cmd script to your composer.json:
{
"scripts": {
"post-update-cmd": [
"@php -r \"@mkdir('bin', 0755, true);\"",
"@php -r \"copy('vendor/mathiasgrimm/laravel-cloud-binaries/bin/jpegoptim', 'bin/jpegoptim');\"",
"@php -r \"copy('vendor/mathiasgrimm/laravel-cloud-binaries/bin/optipng', 'bin/optipng');\"",
"@php -r \"copy('vendor/mathiasgrimm/laravel-cloud-binaries/bin/pngquant', 'bin/pngquant');\""
]
}
}
After every composer update, the selected binaries are copied into bin/ automatically. Adjust the list to include only the binaries you need. The @php -r syntax ensures the commands work on all platforms (Linux, macOS, and Windows).
Usage
After installation, the binaries are available in vendor/bin/:
vendor/bin/jpegoptim --strip-all image.jpg vendor/bin/optipng -o2 image.png vendor/bin/pngquant --quality=65-80 image.png vendor/bin/cwebp -q 80 image.png -o image.webp vendor/bin/dwebp image.webp -o image.png vendor/bin/avifenc image.png image.avif vendor/bin/avifdec image.avif image.png vendor/bin/gifsicle -O3 animation.gif -o optimized.gif vendor/bin/ffmpeg -i input.mp4 -c:v libx264 output.mp4 vendor/bin/ffprobe -v quiet -print_format json -show_format input.mp4 vendor/bin/magick input.png -resize 50% output.png
Note: These are statically compiled Linux (musl) binaries. They will work on Laravel Cloud and other Linux environments but not on macOS or Windows.
Building from source
Prerequisites
- Docker
make
Build all binaries
make
Binaries are output to the bin/ directory.
Build a single binary
make bin/jpegoptim make bin/optipng make bin/pngquant make bin/cwebp make bin/dwebp make bin/avifenc make bin/avifdec make bin/gifsicle make bin/ffmpeg make bin/ffprobe make bin/magick
Parallel builds
make -j4
Testing
Verify that all binaries work correctly by running them inside an Alpine Docker container:
make test # build (if needed) + test make test-only # test without rebuilding
Clean up
make clean # remove bin/ contents make clean-images # remove Docker images make clean-all # both
How it works
Each tool has its own Dockerfile under <tool>/Dockerfile. The Dockerfiles use multi-stage Alpine builds:
- Builder stage — installs dependencies, clones source, compiles with static linking flags
- Final stage —
FROM scratch, copies only the static binary
The Makefile orchestrates building the Docker images and extracting the binaries into bin/.
mathiasgrimm/laravel-cloud-binaries 适用场景与选型建议
mathiasgrimm/laravel-cloud-binaries 是一款 基于 Dockerfile 开发的 Composer 扩展包,目前已累计 892 次下载、GitHub Stars 达 10, 最近一次更新时间为 2026 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mathiasgrimm/laravel-cloud-binaries 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mathiasgrimm/laravel-cloud-binaries 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 892
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-18