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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user