Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thaqebon
Copy link
Contributor

@thaqebon thaqebon commented Feb 6, 2025

Description

This PR enables alpha color conversion between Hex, Hsla, and Rgba formats.

$rgba = new Rgba(55, 155, 255, 0.5);

$hex = $rgba->toHex();
$hexString = (string) $hex; // '#379bff80'
$hexAlpha = $hex->alpha(); // '80'

$newRgba = $hex->toRgba();
$newRgbaString = (string) $newRgba; // rgba(55,155,255,0.5)
$newRgbaAlpha = $newRgba->alpha(); // 0.5

For non-alpha color systems, the default alpha value will be used as 1 (or 'ff'). You can still pass a custom alpha value.

- Update `toHex()`, `toHsla()` and `toRgba()` methods
@freekmurze freekmurze merged commit 142af7f into spatie:main Feb 10, 2025
20 checks passed
@freekmurze
Copy link
Member

Thanks!

@thaqebon thaqebon deleted the alpha-to-alpha-color branch February 10, 2025 12:59
@ralphjsmit
Copy link

This PR was actually a breaking change in my application, because the contract definition changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants