Mail-SpamAssassin

 view release on metacpan or  search on metacpan

lib/Mail/SpamAssassin/HTML/Color.pm  view on Meta::CPAN

    # Apply whiteness and blackness to compute final RGB values
    my $i = 1 - $whiteness - $blackness;
    my @rgb = map { _round(($whiteness + $i * $_) * 255) } @rgb_base;

    return @rgb;
}

sub _parse_angle {
    my ($angle) = @_;

    croak("Invalid color angle: $angle") unless $angle =~ /^(?:none|[+-]?\d*\.?\d+(?:deg|grad|rad|turn)?)$/;

    $angle = $angle =~ s/deg$// ? $angle
        : $angle =~ s/grad$// ? $angle * 360 / 400
        : $angle =~ s/rad$// ? $angle * 180 / 3.14159
        : $angle =~ s/turn$// ? $angle * 360
        : $angle;

    return _round($angle) % 360;

}

sub _round {
    my ($value) = @_;
    return int($value + 0.5);
}

1;

__END__

=head1 NAME

Mail::SpamAssassin::HTML::Color - A class to parse and manipulate CSS color values

=head1 SYNOPSIS

  use Mail::SpamAssassin::HTML::Color;

  my $color = Mail::SpamAssassin::HTML::Color->new('rgba(255, 0, 153, 0.5)');
  $color->blend([255, 255, 255]);
  my $distance = $color->distance([0, 0, 0]);
  print "$color";  # Outputs the color as a hex string

=head1 DESCRIPTION

This class provides methods to parse various CSS color formats, blend them with a background color, calculate the distance between two colors, and convert the color to a hex string.

=head1 METHODS

=head2 new($color)

Creates a new color object from a CSS color string.

=head2 blend($background)

Blends the color with the given background color. Modifies the color in-place and returns the modified object.

=head2 distance($other_color)

Calculates the distance between the current color and another color using a brightness-weighted geometric formula.

=head2 as_hex

Returns the color as a hex string with a leading '#'.

=head2 as_array

Returns the color as an array of RGB values.

=cut



( run in 1.099 second using v1.01-cache-2.11-cpan-437f7b0c052 )