dialloibrahima/intervention-image-mask
Composer 安装命令:
composer require dialloibrahima/intervention-image-mask
包简介
Adds mask() and opacity() modifiers to Intervention Image v3
README 文档
README
🎭 Restore the beloved
mask()andopacity()methods removed in Intervention Image v3
🚀 Why This Package?
With the release of Intervention Image v3, the popular mask() and opacity() methods were removed. This package brings them back as clean, framework-agnostic modifiers that work seamlessly with both GD and Imagick drivers.
✨ Features
- 🎭 Apply masks to images using alpha channels
- 🔮 Control opacity with precise float values (0.0 to 1.0)
- 🖼️ Dual driver support - Works with both GD and Imagick
- ⚡ Zero configuration - Just install and use
- 🧪 Fully tested - 17 tests with 25 assertions
- 📦 Lightweight - No extra dependencies beyond Intervention Image
📦 Installation
composer require dialloibrahima/intervention-image-mask
Requirements
- PHP 8.3 or higher
- Intervention Image 3.0 or higher
- GD or Imagick PHP extension
🎯 Quick Start
Apply a Mask
Use a mask image to define transparency. The mask's alpha channel determines which parts of the original image become transparent.
use DialloIbrahima\InterventionMask\ApplyMask; use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver; $manager = new ImageManager(new Driver()); // Load your image and mask $image = $manager->read('photo.jpg'); $mask = $manager->read('mask.png'); // Apply the mask $result = $image->modify(new ApplyMask($mask)); // Save the result $result->toPng()->save('masked-photo.png');
Set Opacity
Control the transparency level of an entire image with a simple float value.
use DialloIbrahima\InterventionMask\SetOpacity; $image = $manager->read('photo.png'); // 50% opacity $result = $image->modify(new SetOpacity(0.5)); $result->toPng()->save('semi-transparent.png');
📖 API Reference
ApplyMask
Applies a mask image to define transparency regions.
new ApplyMask(ImageInterface $mask)
| Parameter | Type | Description |
|---|---|---|
$mask |
ImageInterface |
The mask image. Its alpha channel defines transparency. |
How it works:
- White areas (or opaque) in the mask → Image is visible
- Black areas (or transparent) in the mask → Image becomes transparent
- Gray areas → Partial transparency
SetOpacity
Sets the overall opacity level of an image.
new SetOpacity(float $opacity)
| Parameter | Type | Description |
|---|---|---|
$opacity |
float |
Opacity level from 0.0 (fully transparent) to 1.0 (fully opaque) |
Examples:
0.0→ Completely invisible0.5→ 50% transparent1.0→ Fully opaque (no change)
💡 Use Cases
🧩 Puzzle Piece Effect
$piece = $manager->read('puzzle-background.jpg'); $shape = $manager->read('puzzle-piece-shape.png'); $puzzlePiece = $piece->modify(new ApplyMask($shape));
🖼️ Image Watermark with Transparency
$watermark = $manager->read('logo.png'); $fadedWatermark = $watermark->modify(new SetOpacity(0.3));
📸 Vignette Effect
$photo = $manager->read('portrait.jpg'); $vignette = $manager->read('vignette-mask.png'); $vintagePhoto = $photo->modify(new ApplyMask($vignette));
🎨 Gradient Fade
$image = $manager->read('landscape.jpg'); $gradientMask = $manager->read('horizontal-gradient.png'); $fadedImage = $image->modify(new ApplyMask($gradientMask));
🔧 Using with Imagick
The package automatically detects and uses the appropriate driver:
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; $manager = new ImageManager(new ImagickDriver()); // Same API - driver is detected automatically $result = $image->modify(new ApplyMask($mask));
🧪 Testing
composer test
Run static analysis:
composer analyse
Format code with Pint:
composer format
📄 License
The MIT License (MIT). Please see License File for more information.
🙏 Credits
- Ibrahima Diallo
- Inspired by the original Intervention Image v2 implementation
Made with ❤️ for the PHP community
dialloibrahima/intervention-image-mask 适用场景与选型建议
dialloibrahima/intervention-image-mask 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 149 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「image」 「gd」 「imagick」 「mask」 「intervention」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dialloibrahima/intervention-image-mask 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dialloibrahima/intervention-image-mask 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dialloibrahima/intervention-image-mask 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Stand-alone zoomify tile generator (format Zoomify) for use with OpenSeadragon, OpenLayers and various viewers.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Image manipulation library for Laravel 8 based on Imagine and inspired by Croppa for easy url based manipulation
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Php library for converting and caching images to Webp .webp, JpegXr .jxr, Jpeg 2000 .jp2
统计信息
- 总下载量: 149
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-10