-
Notifications
You must be signed in to change notification settings - Fork 205
Bug: Watermark::getAlpha() returns 0-100 range but Intervention Image v4 expects 0-1 #449
Copy link
Copy link
Open
Description
Description
Watermark::getAlpha() returns an int in the 0-100 range (defaulting to 100), but Intervention Image v4's InsertModifier expects a float in the 0-1 range. This causes an InvalidArgumentException on every request that applies a watermark.
Versions
league/glide:4.0.0-beta1intervention/image:4.0.0
Error
Intervention\Image\Exceptions\InvalidArgumentException: Transparency must be in range 0 to 1
at vendor/intervention/image/src/Modifiers/InsertModifier.php:26
Root Cause
In src/Manipulators/Watermark.php:265-278:
public function getAlpha(): int
{
$markalpha = $this->getParam('markalpha');
if (!is_numeric($markalpha)) {
return 100;
}
if ($markalpha < 0 || $markalpha > 100) {
return 100;
}
return (int) $markalpha;
}This value is passed directly to Image::insert() on line 117:
return $image->insert($watermark, intval($markx), intval($marky), $markpos, $markalpha);However, Intervention Image v4's InsertModifier::__construct() validates that transparency is between 0 and 1:
public function __construct(
public mixed $image,
public int $x = 0,
public int $y = 0,
public string|Alignment $alignment = Alignment::TOP_LEFT,
public float $transparency = 1
) {
if ($this->transparency < 0 || $this->transparency > 1) {
throw new InvalidArgumentException('Transparency must be in range 0 to 1');
}
}Suggested Fix
Normalize the 0-100 integer to a 0-1 float in getAlpha():
public function getAlpha(): float
{
$markalpha = $this->getParam('markalpha');
if (!is_numeric($markalpha)) {
return 1.0;
}
if ($markalpha < 0 || $markalpha > 100) {
return 1.0;
}
return (float) $markalpha / 100;
}Steps to Reproduce
- Configure a Glide server with a watermark filesystem
- Set a default
markparameter (nomarkalphaoverride needed — the default100triggers it) - Request any image — the watermark manipulator throws on every request
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels