1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 01:51:43 +02:00

Update color picking method of GD driver

This commit is contained in:
Oliver Vogel
2023-10-30 10:58:28 +01:00
parent c760048186
commit b9a3f8c4b2
2 changed files with 22 additions and 3 deletions

View File

@@ -92,9 +92,11 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface
{
return $this->integerToColor(
imagecolorat($this->frame($frame_key)->core(), $x, $y)
);
$gd = $this->frame($frame_key)->core();
$index = imagecolorat($gd, $x, $y);
$colors = imagecolorsforindex($gd, $index);
return $this->arrayToColor($colors);
}
/**

View File

@@ -6,6 +6,23 @@ use Intervention\Image\Colors\Rgb\Color;
trait CanHandleColors
{
/**
* Transforms array result from imagecolorsforindex() to Color object
*
* @param array $values
* @return Color
*/
protected function arrayToColor(array $values): Color
{
list($r, $g, $b, $a) = array_values($values);
// convert gd apha integer to intervention alpha integer
// ([opaque]0-127[transparent]) to ([opaque]255-0[transparent])
$a = (int) static::convertRange($a, 127, 0, 0, 255);
return new Color($r, $g, $b, $a);
}
/**
* Transforms GD Library integer color value to RGB color object
*