Skip to content

Commit

Permalink
Merge branch 'develop' into feature/output-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Aug 13, 2024
2 parents 02295f1 + 54aa51e commit ae9b337
Show file tree
Hide file tree
Showing 124 changed files with 1,062 additions and 67 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
github: [Intervention]
ko_fi: interventionphp
custom: https://paypal.me/interventionio
24 changes: 24 additions & 0 deletions .github/images/support.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
imagemagick: [ '6.9.12-55', '7.1.1-32' ]
imagick: [ '3.7.0' ]
stability: [ prefer-stable ]
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Latest Version](https://img.shields.io/packagist/v/intervention/image.svg)](https://packagist.org/packages/intervention/image)
[![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)
[![Support me on Ko-fi](https://raw.githubusercontent.com/Intervention/image/develop/.github/images/support.svg)](https://ko-fi.com/interventionphp)

Intervention Image is a **PHP image processing library** that provides a simple
and expressive way to create, edit, and compose images. It features a unified
Expand Down
10 changes: 10 additions & 0 deletions src/Colors/Cmyk/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
18 changes: 18 additions & 0 deletions src/Colors/Hsl/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

class Color extends AbstractColor
{
/**
* Create new color object
*
* @param int $h
* @param int $s
* @param int $l
* @return void
*/
public function __construct(int $h, int $s, int $l)
{
/** @throws void */
Expand Down Expand Up @@ -120,4 +128,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
18 changes: 18 additions & 0 deletions src/Colors/Hsv/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

class Color extends AbstractColor
{
/**
* Create new color object
*
* @param int $h
* @param int $s
* @param int $v
* @return void
*/
public function __construct(int $h, int $s, int $v)
{
/** @throws void */
Expand Down Expand Up @@ -120,4 +128,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Colors/Rgb/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,14 @@ public function isTransparent(): bool
{
return $this->alpha()->value() < $this->alpha()->max();
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return $this->alpha()->value() == 0;
}
}
5 changes: 5 additions & 0 deletions src/Colors/Rgb/Decoders/TransparentColorDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

class TransparentColorDecoder extends HexColorDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
Expand Down
11 changes: 11 additions & 0 deletions src/Decoders/EncodedImageObjectDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Decoders;

use Intervention\Image\Drivers\SpecializableDecoder;

class EncodedImageObjectDecoder extends SpecializableDecoder
{
}
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/ColorspaceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class ColorspaceAnalyzer extends GenericColorspaceAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return new Colorspace();
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/HeightAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

class HeightAnalyzer extends GenericHeightAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return imagesy($image->core()->native());
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return $this->colorAt(
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/PixelColorsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

class PixelColorsAnalyzer extends PixelColorAnalyzer
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
$colors = new Collection();
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/ResolutionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class ResolutionAnalyzer extends GenericResolutionAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return new Resolution(...imageresolution($image->core()->native()));
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Analyzers/WidthAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

class WidthAnalyzer extends GenericWidthAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*/
public function analyze(ImageInterface $image): mixed
{
return imagesx($image->core()->native());
Expand Down
12 changes: 8 additions & 4 deletions src/Drivers/Gd/Cloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Intervention\Image\Drivers\Gd;

use GdImage;
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Geometry\Rectangle;
Expand Down Expand Up @@ -50,10 +51,7 @@ public static function cloneEmpty(
ColorInterface $background = new Color(255, 255, 255, 0)
): GdImage {
// define size
$size = match (true) {
is_null($size) => new Rectangle(imagesx($gd), imagesy($gd)),
default => $size,
};
$size = $size ? $size : new Rectangle(imagesx($gd), imagesy($gd));

// create new gd image with same size or new given size
$clone = imagecreatetruecolor($size->width(), $size->height());
Expand All @@ -70,6 +68,12 @@ public static function cloneEmpty(
imagealphablending($clone, true);
imagesavealpha($clone, true);

// set background image as transparent if alpha channel value if color is below .5
// comes into effect when the end format only supports binary transparency (like GIF)
if ($background->channel(Alpha::class)->value() < 128) {
imagecolortransparent($clone, $processor->colorToNative($background));
}

return $clone;
}

Expand Down
16 changes: 16 additions & 0 deletions src/Drivers/Gd/ColorProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@

class ColorProcessor implements ColorProcessorInterface
{
/**
* Create new color processor object
*
* @param ColorspaceInterface $colorspace
* @return void
*/
public function __construct(protected ColorspaceInterface $colorspace = new Colorspace())
{
}

/**
* {@inheritdoc}
*
* @see ColorProcessorInterface::colorToNative()
*/
public function colorToNative(ColorInterface $color): int
{
// convert color to colorspace
Expand All @@ -39,6 +50,11 @@ public function colorToNative(ColorInterface $color): int
return ($a << 24) + ($r << 16) + ($g << 8) + $b;
}

/**
* {@inheritdoc}
*
* @see ColorProcessorInterface::nativeToColor()
*/
public function nativeToColor(mixed $value): ColorInterface
{
if (!is_int($value)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Decoders/Base64ImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class Base64ImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!$this->isValidBase64($input)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Decoders/DataUriImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class DataUriImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
Expand Down
27 changes: 27 additions & 0 deletions src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Intervention\Image\Drivers\Gd\Decoders;

use Intervention\Image\EncodedImage;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ColorInterface;

class EncodedImageObjectDecoder extends BinaryImageDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, EncodedImage::class)) {
throw new DecoderException('Unable to decode input');
}

return parent::decode($input->toString());
}
}
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Decoders/FilePathImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class FilePathImageDecoder extends NativeObjectDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!$this->isFile($input)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Decoders/FilePointerImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

class FilePointerImageDecoder extends BinaryImageDecoder
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_resource($input) || !in_array(get_resource_type($input), ['file', 'stream'])) {
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class SplFileInfoImageDecoder extends FilePathImageDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*/
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_a($input, SplFileInfo::class)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Drivers/Gd/Encoders/AvifEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

class AvifEncoder extends GenericAvifEncoder implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see EncoderInterface::encode()
*/
public function encode(ImageInterface $image): EncodedImage
{
$gd = $image->core()->native();
Expand Down
Loading

0 comments on commit ae9b337

Please sign in to comment.