1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 01:00:06 +02:00

Merge branch 'next' into feature/draw

This commit is contained in:
Oliver Vogel
2022-07-19 17:31:54 +02:00
8 changed files with 281 additions and 20 deletions

View File

@@ -5,12 +5,12 @@
[![Build Status](https://github.com/Intervention/image/actions/workflows/run-tests.yml/badge.svg)](https://github.com/Intervention/image/actions)
[![Monthly Downloads](https://img.shields.io/packagist/dm/intervention/image.svg)](https://packagist.org/packages/intervention/image/stats)
Intervention Image is a **PHP image handling and manipulation** library providing an easier and expressive way to create, edit, and compose images.
Intervention Image is a **image handling and manipulation library written in PHP** providing an easier and expressive way to create, edit, and compose images. GD library or Imagick can be selected as the base layer for all operations.
- Simple interface for
- Driver agnostic
- Simple interface for common tasks
- Interchangable driver architecture
- Support for animated images
- Framework-agnostic, will work with any project
- Framework-agnostic
- PSR-12 compliant
## Code Examples
@@ -20,7 +20,7 @@ Intervention Image is a **PHP image handling and manipulation** library providin
$manager = new ImageManager('gd')
// open an image file
$image = $manager->make('images/example.jpg');
$image = $manager->make('images/example.gif');
// resize image instance
$image->resize(320, 240);
@@ -52,10 +52,10 @@ composer require intervention/image
## Getting started
Learn the [basics](https://image.intervention.io/) on how to use Intervention Image and more with the [official documentation](https://image.intervention.io/).
Learn the [basics](https://image.intervention.io/v3/basics/instantiation/) on how to use Intervention Image and more with the [official documentation](https://image.intervention.io/v3/).
## License
Intervention Image is licensed under the [MIT License](http://opensource.org/licenses/MIT).
Copyright 2021 Oliver Vogel
Copyright 2022 Oliver Vogel

View File

@@ -0,0 +1,28 @@
<?php
namespace Intervention\Image\Drivers\Gd\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanReadHtmlColorNames;
class HtmlColorNameDecoder extends HexColorDecoder
{
use CanReadHtmlColorNames;
public function decode($input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$hexcolor = $this->hexColorFromColorName($input);
if (empty($hexcolor)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode($hexcolor);
}
}

View File

@@ -11,13 +11,15 @@ class InputHandler extends AbstractInputHandler
{
return new Decoders\ImageObjectDecoder(
new Decoders\ArrayColorDecoder(
new Decoders\RgbStringColorDecoder(
new Decoders\HexColorDecoder(
new Decoders\TransparentColorDecoder(
new Decoders\FilePathImageDecoder(
new Decoders\BinaryImageDecoder(
new Decoders\DataUriImageDecoder(
new Decoders\Base64ImageDecoder()
new Decoders\HtmlColorNameDecoder(
new Decoders\RgbStringColorDecoder(
new Decoders\HexColorDecoder(
new Decoders\TransparentColorDecoder(
new Decoders\FilePathImageDecoder(
new Decoders\BinaryImageDecoder(
new Decoders\DataUriImageDecoder(
new Decoders\Base64ImageDecoder()
)
)
)
)

View File

@@ -0,0 +1,28 @@
<?php
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanReadHtmlColorNames;
class HtmlColorNameDecoder extends HexColorDecoder
{
use CanReadHtmlColorNames;
public function decode($input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
$hexcolor = $this->hexColorFromColorName($input);
if (empty($hexcolor)) {
throw new DecoderException('Unable to decode input');
}
return parent::decode($hexcolor);
}
}

View File

@@ -12,12 +12,14 @@ class InputHandler extends AbstractInputHandler
return new Decoders\ImageObjectDecoder(
new Decoders\ArrayColorDecoder(
new Decoders\HexColorDecoder(
new Decoders\RgbStringColorDecoder(
new Decoders\TransparentColorDecoder(
new Decoders\FilePathImageDecoder(
new Decoders\BinaryImageDecoder(
new Decoders\DataUriImageDecoder(
new Decoders\Base64ImageDecoder()
new Decoders\HtmlColorNameDecoder(
new Decoders\RgbStringColorDecoder(
new Decoders\TransparentColorDecoder(
new Decoders\FilePathImageDecoder(
new Decoders\BinaryImageDecoder(
new Decoders\DataUriImageDecoder(
new Decoders\Base64ImageDecoder()
)
)
)
)

View File

@@ -0,0 +1,165 @@
<?php
namespace Intervention\Image\Traits;
trait CanReadHtmlColorNames
{
protected $color_names = [
'lightsalmon' => '#FFA07A',
'salmon' => '#FA8072',
'darksalmon' => '#E9967A',
'lightcoral' => '#F08080',
'indianred' => '#CD5C5C',
'crimson' => '#DC143C',
'firebrick' => '#B22222',
'red' => '#FF0000',
'darkred' => '#8B0000',
'coral' => '#FF7F50',
'tomato' => '#FF6347',
'orangered' => '#FF4500',
'gold' => '#FFD700',
'orange' => '#FFA500',
'darkorange' => '#FF8C00',
'lightyellow' => '#FFFFE0',
'lemonchiffon' => '#FFFACD',
'lightgoldenrodyellow' => '#FAFAD2',
'papayawhip' => '#FFEFD5',
'moccasin' => '#FFE4B5',
'peachpuff' => '#FFDAB9',
'palegoldenrod' => '#EEE8AA',
'khaki' => '#F0E68C',
'darkkhaki' => '#BDB76B',
'yellow' => '#FFFF00',
'lawngreen' => '#7CFC00',
'chartreuse' => '#7FFF00',
'limegreen' => '#32CD32',
'lime' => '#00FF00',
'forestgreen' => '#228B22',
'green' => '#008000',
'darkgreen' => '#006400',
'greenyellow' => '#ADFF2F',
'yellowgreen' => '#9ACD32',
'springgreen' => '#00FF7F',
'mediumspringgreen' => '#00FA9A',
'lightgreen' => '#90EE90',
'palegreen' => '#98FB98',
'darkseagreen' => '#8FBC8F',
'mediumseagre' => 'en #3CB371',
'seagreen' => '#2E8B57',
'olive' => '#808000',
'darkolivegreen' => '#556B2F',
'olivedrab' => '#6B8E23',
'lightcyan' => '#E0FFFF',
'cyan' => '#00FFFF',
'aqua' => '#00FFFF',
'aquamarine' => '#7FFFD4',
'mediumaquamarine' => '#66CDAA',
'paleturquoise' => '#AFEEEE',
'turquoise' => '#40E0D0',
'mediumturquoise' => '#48D1CC',
'darkturquoise' => '#00CED1',
'lightseagreen' => '#20B2AA',
'cadetblue' => '#5F9EA0',
'darkcyan' => '#008B8B',
'teal' => '#008080',
'powderblue' => '#B0E0E6',
'lightblue' => '#ADD8E6',
'lightskyblue' => '#87CEFA',
'skyblue' => '#87CEEB',
'deepskyblue' => '#00BFFF',
'lightsteelblue' => '#B0C4DE',
'dodgerblue' => '#1E90FF',
'cornflowerblue' => '#6495ED',
'steelblue' => '#4682B4',
'royalblue' => '#4169E1',
'blue' => '#0000FF',
'mediumblue' => '#0000CD',
'darkblue' => '#00008B',
'navy' => '#000080',
'midnightblue' => '#191970',
'mediumslateblue' => '#7B68EE',
'slateblue' => '#6A5ACD',
'darkslateblue' => '#483D8B',
'lavender' => '#E6E6FA',
'thistle' => '#D8BFD8',
'plum' => '#DDA0DD',
'violet' => '#EE82EE',
'orchid' => '#DA70D6',
'fuchsia' => '#FF00FF',
'magenta' => '#FF00FF',
'mediumorchid' => '#BA55D3',
'mediumpurple' => '#9370DB',
'blueviolet' => '#8A2BE2',
'darkviolet' => '#9400D3',
'darkorchid' => '#9932CC',
'darkmagenta' => '#8B008B',
'purple' => '#800080',
'indigo' => '#4B0082',
'pink' => '#FFC0CB',
'lightpink' => '#FFB6C1',
'hotpink' => '#FF69B4',
'deeppink' => '#FF1493',
'palevioletred' => '#DB7093',
'mediumvioletred' => '#C71585',
'white' => '#FFFFFF',
'snow' => '#FFFAFA',
'honeydew' => '#F0FFF0',
'mintcream' => '#F5FFFA',
'azure' => '#F0FFFF',
'aliceblue' => '#F0F8FF',
'ghostwhite' => '#F8F8FF',
'whitesmoke' => '#F5F5F5',
'seashell' => '#FFF5EE',
'beige' => '#F5F5DC',
'oldlace' => '#FDF5E6',
'floralwhite' => '#FFFAF0',
'ivory' => '#FFFFF0',
'antiquewhite' => '#FAEBD7',
'linen' => '#FAF0E6',
'lavenderblush' => '#FFF0F5',
'mistyrose' => '#FFE4E1',
'gainsboro' => '#DCDCDC',
'lightgray' => '#D3D3D3',
'silver' => '#C0C0C0',
'darkgray' => '#A9A9A9',
'gray' => '#808080',
'dimgray' => '#696969',
'lightslategray' => '#778899',
'slategray' => '#708090',
'darkslategray' => '#2F4F4F',
'black' => '#000000',
'cornsilk' => '#FFF8DC',
'blanchedalmond' => '#FFEBCD',
'bisque' => '#FFE4C4',
'navajowhite' => '#FFDEAD',
'wheat' => '#F5DEB3',
'burlywood' => '#DEB887',
'tan' => '#D2B48C',
'rosybrown' => '#BC8F8F',
'sandybrown' => '#F4A460',
'goldenrod' => '#DAA520',
'peru' => '#CD853F',
'chocolate' => '#D2691E',
'saddlebrown' => '#8B4513',
'sienna' => '#A0522D',
'brown' => '#A52A2A',
'maroon' => '#800000',
];
/**
* Transform given html color name to hex color
* or return null, if color name doesn't exist.
*
* @param string $name
* @return null|string
*/
public function hexColorFromColorName(string $name): ?string
{
$name = strtolower($name);
if (!array_key_exists($name, $this->color_names)) {
return null;
}
return $this->color_names[$name];
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Intervention\Image\Tests\Drivers\Gd\Decoders;
use Intervention\Image\Drivers\Gd\Color;
use Intervention\Image\Drivers\Gd\Decoders\HtmlColorNameDecoder;
use Intervention\Image\Tests\TestCase;
class HtmlColorNameDecoderTest extends TestCase
{
public function testDecode(): void
{
$decoder = new HtmlColorNameDecoder();
$color = $decoder->decode('tomato');
$this->assertInstanceOf(Color::class, $color);
$this->assertEquals('ff6347', $color->toHex());
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Intervention\Image\Tests\Drivers\Imagick\Decoders;
use Intervention\Image\Drivers\Imagick\Color;
use Intervention\Image\Drivers\Imagick\Decoders\HtmlColorNameDecoder;
use Intervention\Image\Tests\TestCase;
class HtmlColorNameDecoderTest extends TestCase
{
public function testDecode(): void
{
$decoder = new HtmlColorNameDecoder();
$color = $decoder->decode('tomato');
$this->assertInstanceOf(Color::class, $color);
$this->assertEquals('ff6347', $color->toHex());
}
}