From 95e72b877b38f96e52996a0ab367ebc64a249395 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 21 Oct 2021 14:32:05 +0200 Subject: [PATCH] Version 3 prototype --- .travis.yml | 36 - LICENSE | 9 - README.md | 55 - composer.json | 37 +- phpunit.xml | 1 - provides.json | 11 - src/Collection.php | 137 ++ src/Drivers/Abstract/AbstractColor.php | 17 + src/Drivers/Abstract/AbstractFrame.php | 8 + src/Drivers/Abstract/AbstractImage.php | 81 + src/Drivers/Abstract/AbstractInputHandler.php | 17 + .../Abstract/Decoders/AbstractDecoder.php | 47 + .../Abstract/Encoders/AbstractEncoder.php | 41 + src/Drivers/Gd/Color.php | 57 + src/Drivers/Gd/Decoders/ArrayColorDecoder.php | 33 + .../Gd/Decoders/Base64ImageDecoder.php | 22 + .../Gd/Decoders/BinaryImageDecoder.php | 55 + .../Gd/Decoders/DataUriImageDecoder.php | 33 + .../Gd/Decoders/FilePathImageDecoder.php | 28 + src/Drivers/Gd/Encoders/GifEncoder.php | 33 + src/Drivers/Gd/Encoders/JpegEncoder.php | 17 + src/Drivers/Gd/Frame.php | 111 ++ src/Drivers/Gd/Image.php | 36 + src/Drivers/Gd/ImageFactory.php | 19 + src/Drivers/Gd/InputHandler.php | 22 + .../Gd/Modifiers/GreyscaleModifier.php | 18 + src/Drivers/Imagick/Color.php | 53 + .../Imagick/Decoders/ArrayColorDecoder.php | 31 + .../Imagick/Decoders/Base64ImageDecoder.php | 22 + .../Imagick/Decoders/BinaryImageDecoder.php | 34 + .../Imagick/Decoders/DataUriImageDecoder.php | 33 + .../Imagick/Decoders/FilePathImageDecoder.php | 28 + src/Drivers/Imagick/Encoders/GifEncoder.php | 29 + src/Drivers/Imagick/Encoders/JpegEncoder.php | 29 + src/Drivers/Imagick/Frame.php | 83 + src/Drivers/Imagick/Image.php | 35 + src/Drivers/Imagick/InputHandler.php | 22 + .../Imagick/Modifiers/GreyscaleModifier.php | 18 + src/Exceptions/DecoderException.php | 8 + src/Exceptions/NotWritableException.php | 8 + src/Exceptions/RuntimeException.php | 8 + src/Geometry/Point.php | 135 ++ src/Geometry/Size.php | 92 + src/ImageManager.php | 96 + src/Interfaces/CollectionInterface.php | 12 + src/Interfaces/ColorInterface.php | 13 + src/Interfaces/DecoderInterface.php | 8 + src/Interfaces/EncoderInterface.php | 8 + src/Interfaces/FactoryInterface.php | 8 + src/Interfaces/FrameInterface.php | 18 + src/Interfaces/ImageInterface.php | 12 + src/Interfaces/ModifierInterface.php | 8 + src/Interfaces/PointInterface.php | 9 + src/Interfaces/SizeInterface.php | 16 + src/Intervention/Image/AbstractColor.php | 229 --- src/Intervention/Image/AbstractDecoder.php | 364 ---- src/Intervention/Image/AbstractDriver.php | 140 -- src/Intervention/Image/AbstractEncoder.php | 271 --- src/Intervention/Image/AbstractFont.php | 295 --- src/Intervention/Image/AbstractShape.php | 71 - .../Image/Commands/AbstractCommand.php | 81 - src/Intervention/Image/Commands/Argument.php | 225 --- .../Image/Commands/ChecksumCommand.php | 29 - .../Image/Commands/CircleCommand.php | 35 - .../Image/Commands/EllipseCommand.php | 36 - .../Image/Commands/ExifCommand.php | 61 - .../Image/Commands/IptcCommand.php | 68 - .../Image/Commands/LineCommand.php | 36 - .../Image/Commands/OrientateCommand.php | 48 - .../Image/Commands/PolygonCommand.php | 49 - .../Image/Commands/PsrResponseCommand.php | 45 - .../Image/Commands/RectangleCommand.php | 36 - .../Image/Commands/ResponseCommand.php | 26 - .../Image/Commands/StreamCommand.php | 39 - .../Image/Commands/TextCommand.php | 34 - src/Intervention/Image/Constraint.php | 92 - .../Image/Exception/ImageException.php | 8 - .../Exception/InvalidArgumentException.php | 8 - .../Exception/MissingDependencyException.php | 8 - .../Image/Exception/NotFoundException.php | 8 - .../Image/Exception/NotReadableException.php | 8 - .../Image/Exception/NotSupportedException.php | 8 - .../Image/Exception/NotWritableException.php | 8 - .../Image/Exception/RuntimeException.php | 8 - src/Intervention/Image/Facades/Image.php | 19 - src/Intervention/Image/File.php | 92 - src/Intervention/Image/Filters/DemoFilter.php | 44 - .../Image/Filters/FilterInterface.php | 16 - src/Intervention/Image/Gd/Color.php | 227 --- .../Image/Gd/Commands/BackupCommand.php | 25 - .../Image/Gd/Commands/BlurCommand.php | 25 - .../Image/Gd/Commands/BrightnessCommand.php | 21 - .../Image/Gd/Commands/ColorizeCommand.php | 29 - .../Image/Gd/Commands/ContrastCommand.php | 21 - .../Image/Gd/Commands/CropCommand.php | 40 - .../Image/Gd/Commands/DestroyCommand.php | 27 - .../Image/Gd/Commands/FillCommand.php | 69 - .../Image/Gd/Commands/FitCommand.php | 32 - .../Image/Gd/Commands/FlipCommand.php | 37 - .../Image/Gd/Commands/GammaCommand.php | 21 - .../Image/Gd/Commands/GetSizeCommand.php | 25 - .../Image/Gd/Commands/GreyscaleCommand.php | 19 - .../Image/Gd/Commands/HeightenCommand.php | 28 - .../Image/Gd/Commands/InsertCommand.php | 34 - .../Image/Gd/Commands/InterlaceCommand.php | 23 - .../Image/Gd/Commands/InvertCommand.php | 19 - .../Image/Gd/Commands/LimitColorsCommand.php | 53 - .../Image/Gd/Commands/MaskCommand.php | 83 - .../Image/Gd/Commands/OpacityCommand.php | 31 - .../Image/Gd/Commands/PickColorCommand.php | 37 - .../Image/Gd/Commands/PixelCommand.php | 25 - .../Image/Gd/Commands/PixelateCommand.php | 21 - .../Image/Gd/Commands/ResetCommand.php | 39 - .../Image/Gd/Commands/ResizeCanvasCommand.php | 83 - .../Image/Gd/Commands/ResizeCommand.php | 84 - .../Image/Gd/Commands/RotateCommand.php | 30 - .../Image/Gd/Commands/SharpenCommand.php | 34 - .../Image/Gd/Commands/TrimCommand.php | 176 -- .../Image/Gd/Commands/WidenCommand.php | 28 - src/Intervention/Image/Gd/Decoder.php | 171 -- src/Intervention/Image/Gd/Driver.php | 89 - src/Intervention/Image/Gd/Encoder.php | 180 -- src/Intervention/Image/Gd/Font.php | 277 --- .../Image/Gd/Shapes/CircleShape.php | 40 - .../Image/Gd/Shapes/EllipseShape.php | 65 - .../Image/Gd/Shapes/LineShape.php | 90 - .../Image/Gd/Shapes/PolygonShape.php | 49 - .../Image/Gd/Shapes/RectangleShape.php | 76 - src/Intervention/Image/Image.php | 370 ---- src/Intervention/Image/ImageManager.php | 142 -- src/Intervention/Image/ImageManagerStatic.php | 88 - .../Image/ImageServiceProvider.php | 87 - .../Image/ImageServiceProviderLaravel4.php | 112 -- .../ImageServiceProviderLaravelRecent.php | 106 - .../Image/ImageServiceProviderLeague.php | 42 - .../Image/ImageServiceProviderLumen.php | 34 - src/Intervention/Image/Imagick/Color.php | 279 --- .../Image/Imagick/Commands/BackupCommand.php | 25 - .../Image/Imagick/Commands/BlurCommand.php | 21 - .../Imagick/Commands/BrightnessCommand.php | 21 - .../Imagick/Commands/ColorizeCommand.php | 44 - .../Imagick/Commands/ContrastCommand.php | 21 - .../Image/Imagick/Commands/CropCommand.php | 45 - .../Image/Imagick/Commands/DestroyCommand.php | 27 - .../Image/Imagick/Commands/ExifCommand.php | 63 - .../Image/Imagick/Commands/FillCommand.php | 105 - .../Image/Imagick/Commands/FitCommand.php | 42 - .../Image/Imagick/Commands/FlipCommand.php | 27 - .../Image/Imagick/Commands/GammaCommand.php | 21 - .../Image/Imagick/Commands/GetSizeCommand.php | 28 - .../Imagick/Commands/GreyscaleCommand.php | 19 - .../Imagick/Commands/HeightenCommand.php | 28 - .../Image/Imagick/Commands/InsertCommand.php | 33 - .../Imagick/Commands/InterlaceCommand.php | 29 - .../Image/Imagick/Commands/InvertCommand.php | 19 - .../Imagick/Commands/LimitColorsCommand.php | 59 - .../Image/Imagick/Commands/MaskCommand.php | 60 - .../Image/Imagick/Commands/OpacityCommand.php | 23 - .../Imagick/Commands/PickColorCommand.php | 30 - .../Image/Imagick/Commands/PixelCommand.php | 31 - .../Imagick/Commands/PixelateCommand.php | 27 - .../Image/Imagick/Commands/ResetCommand.php | 40 - .../Imagick/Commands/ResizeCanvasCommand.php | 91 - .../Image/Imagick/Commands/ResizeCommand.php | 29 - .../Image/Imagick/Commands/RotateCommand.php | 30 - .../Image/Imagick/Commands/SharpenCommand.php | 21 - .../Image/Imagick/Commands/TrimCommand.php | 121 -- .../Image/Imagick/Commands/WidenCommand.php | 28 - src/Intervention/Image/Imagick/Decoder.php | 124 -- src/Intervention/Image/Imagick/Driver.php | 74 - src/Intervention/Image/Imagick/Encoder.php | 239 --- src/Intervention/Image/Imagick/Font.php | 122 -- .../Image/Imagick/Shapes/CircleShape.php | 40 - .../Image/Imagick/Shapes/EllipseShape.php | 66 - .../Image/Imagick/Shapes/LineShape.php | 94 - .../Image/Imagick/Shapes/PolygonShape.php | 81 - .../Image/Imagick/Shapes/RectangleShape.php | 84 - src/Intervention/Image/Point.php | 64 - src/Intervention/Image/Response.php | 78 - src/Intervention/Image/Size.php | 374 ---- src/Traits/CanDecodeDataUri.php | 75 + src/Traits/CanResolveDriverClass.php | 48 + src/Traits/CanValidateBase64.php | 15 + src/Traits/CanValidateColorArray.php | 31 + src/config/config.php | 20 - tests/AbstractColorTest.php | 20 - tests/AbstractCommandTest.php | 48 - tests/AbstractDecoderTest.php | 160 -- tests/AbstractDriverTest.php | 21 - tests/AbstractFontTest.php | 86 - tests/AbstractShapeTest.php | 43 - tests/ArgumentTest.php | 422 ---- tests/BackupCommandTest.php | 65 - tests/BlurCommandTest.php | 34 - tests/BrightnessCommandTest.php | 34 - tests/ChecksumCommandTest.php | 27 - tests/CircleCommandTest.php | 43 - tests/CircleShapeTest.php | 52 - tests/CollectionTest.php | 102 + tests/ColorizeCommandTest.php | 37 - tests/ConstraintTest.php | 58 - tests/ContrastCommandTest.php | 34 - tests/CropCommandTest.php | 36 - tests/DestroyCommandTest.php | 46 - tests/DriverTest.php | 61 - tests/Drivers/Gd/ColorTest.php | 75 + .../Gd/Decoders/ArrayColorDecoderTest.php | 21 + .../Gd/Decoders/BinaryImageDecoderTest.php | 40 + tests/Drivers/Gd/Encoders/GifEncoderTest.php | 40 + tests/Drivers/Gd/Encoders/JpegEncoderTest.php | 29 + tests/Drivers/Gd/FrameTest.php | 79 + tests/Drivers/Gd/ImageFactoryTest.php | 17 + tests/Drivers/Gd/ImageTest.php | 46 + tests/Drivers/Gd/InputHandlerTest.php | 62 + tests/Drivers/Imagick/ColorTest.php | 87 + .../Decoders/ArrayColorDecoderTest.php | 21 + .../Imagick/Encoders/GifEncoderTest.php | 42 + .../Imagick/Encoders/JpegEncoderTest.php | 33 + tests/Drivers/Imagick/FrameTest.php | 87 + tests/Drivers/Imagick/ImageTest.php | 51 + tests/Drivers/Imagick/InputHandlerTest.php | 62 + tests/EllipseCommandTest.php | 43 - tests/EllipseShapeTest.php | 55 - tests/EncoderTest.php | 339 ---- tests/ExifCommandTest.php | 112 -- tests/FileTest.php | 28 - tests/FillCommandTest.php | 93 - tests/FitCommandTest.php | 93 - tests/FlipCommandTest.php | 45 - tests/GammaCommandTest.php | 34 - tests/GdColorTest.php | 296 --- tests/GdSystemTest.php | 1703 ----------------- tests/Geometry/PointTest.php | 82 + tests/Geometry/SizeTest.php | 101 + tests/GetsizeCommandTest.php | 39 - tests/GreyscaleCommandTest.php | 34 - tests/HeightenCommandTest.php | 49 - tests/ImageManagerStaticTest.php | 36 - tests/ImageManagerTest.php | 50 +- tests/ImageTest.php | 143 -- tests/ImagickColorTest.php | 338 ---- tests/ImagickSystemTest.php | 1650 ---------------- tests/InsertCommandTest.php | 67 - tests/InterlaceCommandTest.php | 34 - tests/InvertCommandTest.php | 34 - tests/IptcCommandTest.php | 72 - tests/LimitColorsCommandTest.php | 43 - tests/LineCommandTest.php | 43 - tests/LineShapeTest.php | 50 - tests/MaskCommandTest.php | 68 - tests/OpacityCommandTest.php | 44 - tests/OrientateCommandTest.php | 94 - tests/PickColorCommandTest.php | 67 - tests/PixelCommandTest.php | 34 - tests/PixelateCommandTest.php | 37 - tests/PointTest.php | 47 - tests/PolygonCommandTest.php | 45 - tests/PolygonShapeTest.php | 57 - tests/PsrResponseCommandTest.php | 58 - tests/RectangleCommandTest.php | 43 - tests/RectangleShapeTest.php | 54 - tests/ResetCommandTest.php | 71 - tests/ResizeCanvasCommandTest.php | 80 - tests/ResizeCommandTest.php | 49 - tests/ResponseTest.php | 30 - tests/RotateCommandTest.php | 48 - tests/SharpenCommandTest.php | 34 - tests/SizeTest.php | 436 ----- tests/StreamCommandTest.php | 36 - tests/TestCase.php | 17 + tests/TextCommandTest.php | 32 - tests/TrimCommandTest.php | 54 - tests/WidenCommandTest.php | 49 - tests/images/animation.gif | Bin 0 -> 592 bytes tests/images/black-friday.png | Bin 4964 -> 0 bytes tests/images/blue.gif | Bin 0 -> 47 bytes tests/images/broken.png | Bin 42 -> 0 bytes tests/images/cats.gif | Bin 0 -> 1721 bytes tests/images/circle.png | Bin 383 -> 0 bytes tests/images/exif.jpg | Bin 7791 -> 0 bytes tests/images/gradient.png | Bin 531 -> 0 bytes tests/images/green.gif | Bin 0 -> 47 bytes tests/images/iptc.jpg | Bin 10526 -> 0 bytes tests/images/red.gif | Bin 0 -> 47 bytes tests/images/star.png | Bin 463 -> 0 bytes tests/images/test.jpg | Bin 9183 -> 0 bytes tests/images/test.webp | Bin 82 -> 0 bytes tests/images/trim.png | Bin 258 -> 0 bytes tests/tmp/.gitkeep | 0 289 files changed, 3010 insertions(+), 17483 deletions(-) delete mode 100644 .travis.yml delete mode 100644 LICENSE delete mode 100755 README.md delete mode 100644 provides.json create mode 100644 src/Collection.php create mode 100644 src/Drivers/Abstract/AbstractColor.php create mode 100644 src/Drivers/Abstract/AbstractFrame.php create mode 100644 src/Drivers/Abstract/AbstractImage.php create mode 100644 src/Drivers/Abstract/AbstractInputHandler.php create mode 100644 src/Drivers/Abstract/Decoders/AbstractDecoder.php create mode 100644 src/Drivers/Abstract/Encoders/AbstractEncoder.php create mode 100644 src/Drivers/Gd/Color.php create mode 100644 src/Drivers/Gd/Decoders/ArrayColorDecoder.php create mode 100644 src/Drivers/Gd/Decoders/Base64ImageDecoder.php create mode 100644 src/Drivers/Gd/Decoders/BinaryImageDecoder.php create mode 100644 src/Drivers/Gd/Decoders/DataUriImageDecoder.php create mode 100644 src/Drivers/Gd/Decoders/FilePathImageDecoder.php create mode 100644 src/Drivers/Gd/Encoders/GifEncoder.php create mode 100644 src/Drivers/Gd/Encoders/JpegEncoder.php create mode 100644 src/Drivers/Gd/Frame.php create mode 100644 src/Drivers/Gd/Image.php create mode 100644 src/Drivers/Gd/ImageFactory.php create mode 100644 src/Drivers/Gd/InputHandler.php create mode 100644 src/Drivers/Gd/Modifiers/GreyscaleModifier.php create mode 100644 src/Drivers/Imagick/Color.php create mode 100644 src/Drivers/Imagick/Decoders/ArrayColorDecoder.php create mode 100644 src/Drivers/Imagick/Decoders/Base64ImageDecoder.php create mode 100644 src/Drivers/Imagick/Decoders/BinaryImageDecoder.php create mode 100644 src/Drivers/Imagick/Decoders/DataUriImageDecoder.php create mode 100644 src/Drivers/Imagick/Decoders/FilePathImageDecoder.php create mode 100644 src/Drivers/Imagick/Encoders/GifEncoder.php create mode 100644 src/Drivers/Imagick/Encoders/JpegEncoder.php create mode 100644 src/Drivers/Imagick/Frame.php create mode 100644 src/Drivers/Imagick/Image.php create mode 100644 src/Drivers/Imagick/InputHandler.php create mode 100644 src/Drivers/Imagick/Modifiers/GreyscaleModifier.php create mode 100644 src/Exceptions/DecoderException.php create mode 100644 src/Exceptions/NotWritableException.php create mode 100644 src/Exceptions/RuntimeException.php create mode 100644 src/Geometry/Point.php create mode 100644 src/Geometry/Size.php create mode 100644 src/ImageManager.php create mode 100644 src/Interfaces/CollectionInterface.php create mode 100644 src/Interfaces/ColorInterface.php create mode 100644 src/Interfaces/DecoderInterface.php create mode 100644 src/Interfaces/EncoderInterface.php create mode 100644 src/Interfaces/FactoryInterface.php create mode 100644 src/Interfaces/FrameInterface.php create mode 100644 src/Interfaces/ImageInterface.php create mode 100644 src/Interfaces/ModifierInterface.php create mode 100644 src/Interfaces/PointInterface.php create mode 100644 src/Interfaces/SizeInterface.php delete mode 100644 src/Intervention/Image/AbstractColor.php delete mode 100644 src/Intervention/Image/AbstractDecoder.php delete mode 100644 src/Intervention/Image/AbstractDriver.php delete mode 100644 src/Intervention/Image/AbstractEncoder.php delete mode 100644 src/Intervention/Image/AbstractFont.php delete mode 100644 src/Intervention/Image/AbstractShape.php delete mode 100644 src/Intervention/Image/Commands/AbstractCommand.php delete mode 100644 src/Intervention/Image/Commands/Argument.php delete mode 100644 src/Intervention/Image/Commands/ChecksumCommand.php delete mode 100644 src/Intervention/Image/Commands/CircleCommand.php delete mode 100644 src/Intervention/Image/Commands/EllipseCommand.php delete mode 100644 src/Intervention/Image/Commands/ExifCommand.php delete mode 100644 src/Intervention/Image/Commands/IptcCommand.php delete mode 100644 src/Intervention/Image/Commands/LineCommand.php delete mode 100644 src/Intervention/Image/Commands/OrientateCommand.php delete mode 100644 src/Intervention/Image/Commands/PolygonCommand.php delete mode 100644 src/Intervention/Image/Commands/PsrResponseCommand.php delete mode 100644 src/Intervention/Image/Commands/RectangleCommand.php delete mode 100644 src/Intervention/Image/Commands/ResponseCommand.php delete mode 100644 src/Intervention/Image/Commands/StreamCommand.php delete mode 100644 src/Intervention/Image/Commands/TextCommand.php delete mode 100644 src/Intervention/Image/Constraint.php delete mode 100644 src/Intervention/Image/Exception/ImageException.php delete mode 100644 src/Intervention/Image/Exception/InvalidArgumentException.php delete mode 100644 src/Intervention/Image/Exception/MissingDependencyException.php delete mode 100644 src/Intervention/Image/Exception/NotFoundException.php delete mode 100644 src/Intervention/Image/Exception/NotReadableException.php delete mode 100644 src/Intervention/Image/Exception/NotSupportedException.php delete mode 100644 src/Intervention/Image/Exception/NotWritableException.php delete mode 100644 src/Intervention/Image/Exception/RuntimeException.php delete mode 100644 src/Intervention/Image/Facades/Image.php delete mode 100644 src/Intervention/Image/File.php delete mode 100644 src/Intervention/Image/Filters/DemoFilter.php delete mode 100644 src/Intervention/Image/Filters/FilterInterface.php delete mode 100644 src/Intervention/Image/Gd/Color.php delete mode 100644 src/Intervention/Image/Gd/Commands/BackupCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/BlurCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/BrightnessCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/ColorizeCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/ContrastCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/CropCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/DestroyCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/FillCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/FitCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/FlipCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/GammaCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/GetSizeCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/GreyscaleCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/HeightenCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/InsertCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/InterlaceCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/InvertCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/LimitColorsCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/MaskCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/OpacityCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/PickColorCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/PixelCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/PixelateCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/ResetCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/ResizeCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/RotateCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/SharpenCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/TrimCommand.php delete mode 100644 src/Intervention/Image/Gd/Commands/WidenCommand.php delete mode 100644 src/Intervention/Image/Gd/Decoder.php delete mode 100644 src/Intervention/Image/Gd/Driver.php delete mode 100644 src/Intervention/Image/Gd/Encoder.php delete mode 100644 src/Intervention/Image/Gd/Font.php delete mode 100644 src/Intervention/Image/Gd/Shapes/CircleShape.php delete mode 100644 src/Intervention/Image/Gd/Shapes/EllipseShape.php delete mode 100644 src/Intervention/Image/Gd/Shapes/LineShape.php delete mode 100644 src/Intervention/Image/Gd/Shapes/PolygonShape.php delete mode 100644 src/Intervention/Image/Gd/Shapes/RectangleShape.php delete mode 100644 src/Intervention/Image/Image.php delete mode 100644 src/Intervention/Image/ImageManager.php delete mode 100644 src/Intervention/Image/ImageManagerStatic.php delete mode 100644 src/Intervention/Image/ImageServiceProvider.php delete mode 100755 src/Intervention/Image/ImageServiceProviderLaravel4.php delete mode 100644 src/Intervention/Image/ImageServiceProviderLaravelRecent.php delete mode 100644 src/Intervention/Image/ImageServiceProviderLeague.php delete mode 100644 src/Intervention/Image/ImageServiceProviderLumen.php delete mode 100644 src/Intervention/Image/Imagick/Color.php delete mode 100644 src/Intervention/Image/Imagick/Commands/BackupCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/BlurCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/BrightnessCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ColorizeCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ContrastCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/CropCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/DestroyCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ExifCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/FillCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/FitCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/FlipCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/GammaCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/GetSizeCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/GreyscaleCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/HeightenCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/InsertCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/InterlaceCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/InvertCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/MaskCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/OpacityCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/PickColorCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/PixelCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/PixelateCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ResetCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/ResizeCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/RotateCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/SharpenCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/TrimCommand.php delete mode 100644 src/Intervention/Image/Imagick/Commands/WidenCommand.php delete mode 100644 src/Intervention/Image/Imagick/Decoder.php delete mode 100644 src/Intervention/Image/Imagick/Driver.php delete mode 100644 src/Intervention/Image/Imagick/Encoder.php delete mode 100644 src/Intervention/Image/Imagick/Font.php delete mode 100644 src/Intervention/Image/Imagick/Shapes/CircleShape.php delete mode 100644 src/Intervention/Image/Imagick/Shapes/EllipseShape.php delete mode 100644 src/Intervention/Image/Imagick/Shapes/LineShape.php delete mode 100644 src/Intervention/Image/Imagick/Shapes/PolygonShape.php delete mode 100644 src/Intervention/Image/Imagick/Shapes/RectangleShape.php delete mode 100644 src/Intervention/Image/Point.php delete mode 100644 src/Intervention/Image/Response.php delete mode 100644 src/Intervention/Image/Size.php create mode 100644 src/Traits/CanDecodeDataUri.php create mode 100644 src/Traits/CanResolveDriverClass.php create mode 100644 src/Traits/CanValidateBase64.php create mode 100644 src/Traits/CanValidateColorArray.php delete mode 100644 src/config/config.php delete mode 100644 tests/AbstractColorTest.php delete mode 100644 tests/AbstractCommandTest.php delete mode 100644 tests/AbstractDecoderTest.php delete mode 100644 tests/AbstractDriverTest.php delete mode 100644 tests/AbstractFontTest.php delete mode 100644 tests/AbstractShapeTest.php delete mode 100644 tests/ArgumentTest.php delete mode 100644 tests/BackupCommandTest.php delete mode 100644 tests/BlurCommandTest.php delete mode 100644 tests/BrightnessCommandTest.php delete mode 100644 tests/ChecksumCommandTest.php delete mode 100644 tests/CircleCommandTest.php delete mode 100644 tests/CircleShapeTest.php create mode 100644 tests/CollectionTest.php delete mode 100644 tests/ColorizeCommandTest.php delete mode 100644 tests/ConstraintTest.php delete mode 100644 tests/ContrastCommandTest.php delete mode 100644 tests/CropCommandTest.php delete mode 100644 tests/DestroyCommandTest.php delete mode 100644 tests/DriverTest.php create mode 100644 tests/Drivers/Gd/ColorTest.php create mode 100644 tests/Drivers/Gd/Decoders/ArrayColorDecoderTest.php create mode 100644 tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php create mode 100644 tests/Drivers/Gd/Encoders/GifEncoderTest.php create mode 100644 tests/Drivers/Gd/Encoders/JpegEncoderTest.php create mode 100644 tests/Drivers/Gd/FrameTest.php create mode 100644 tests/Drivers/Gd/ImageFactoryTest.php create mode 100644 tests/Drivers/Gd/ImageTest.php create mode 100644 tests/Drivers/Gd/InputHandlerTest.php create mode 100644 tests/Drivers/Imagick/ColorTest.php create mode 100644 tests/Drivers/Imagick/Decoders/ArrayColorDecoderTest.php create mode 100644 tests/Drivers/Imagick/Encoders/GifEncoderTest.php create mode 100644 tests/Drivers/Imagick/Encoders/JpegEncoderTest.php create mode 100644 tests/Drivers/Imagick/FrameTest.php create mode 100644 tests/Drivers/Imagick/ImageTest.php create mode 100644 tests/Drivers/Imagick/InputHandlerTest.php delete mode 100644 tests/EllipseCommandTest.php delete mode 100644 tests/EllipseShapeTest.php delete mode 100644 tests/EncoderTest.php delete mode 100644 tests/ExifCommandTest.php delete mode 100644 tests/FileTest.php delete mode 100644 tests/FillCommandTest.php delete mode 100644 tests/FitCommandTest.php delete mode 100644 tests/FlipCommandTest.php delete mode 100644 tests/GammaCommandTest.php delete mode 100644 tests/GdColorTest.php delete mode 100644 tests/GdSystemTest.php create mode 100644 tests/Geometry/PointTest.php create mode 100644 tests/Geometry/SizeTest.php delete mode 100644 tests/GetsizeCommandTest.php delete mode 100644 tests/GreyscaleCommandTest.php delete mode 100644 tests/HeightenCommandTest.php delete mode 100644 tests/ImageManagerStaticTest.php delete mode 100644 tests/ImageTest.php delete mode 100644 tests/ImagickColorTest.php delete mode 100644 tests/ImagickSystemTest.php delete mode 100644 tests/InsertCommandTest.php delete mode 100644 tests/InterlaceCommandTest.php delete mode 100644 tests/InvertCommandTest.php delete mode 100644 tests/IptcCommandTest.php delete mode 100644 tests/LimitColorsCommandTest.php delete mode 100644 tests/LineCommandTest.php delete mode 100644 tests/LineShapeTest.php delete mode 100644 tests/MaskCommandTest.php delete mode 100644 tests/OpacityCommandTest.php delete mode 100644 tests/OrientateCommandTest.php delete mode 100644 tests/PickColorCommandTest.php delete mode 100644 tests/PixelCommandTest.php delete mode 100644 tests/PixelateCommandTest.php delete mode 100644 tests/PointTest.php delete mode 100644 tests/PolygonCommandTest.php delete mode 100644 tests/PolygonShapeTest.php delete mode 100644 tests/PsrResponseCommandTest.php delete mode 100644 tests/RectangleCommandTest.php delete mode 100644 tests/RectangleShapeTest.php delete mode 100644 tests/ResetCommandTest.php delete mode 100644 tests/ResizeCanvasCommandTest.php delete mode 100644 tests/ResizeCommandTest.php delete mode 100644 tests/ResponseTest.php delete mode 100644 tests/RotateCommandTest.php delete mode 100644 tests/SharpenCommandTest.php delete mode 100644 tests/SizeTest.php delete mode 100644 tests/StreamCommandTest.php create mode 100644 tests/TestCase.php delete mode 100644 tests/TextCommandTest.php delete mode 100644 tests/TrimCommandTest.php delete mode 100644 tests/WidenCommandTest.php create mode 100644 tests/images/animation.gif delete mode 100644 tests/images/black-friday.png create mode 100644 tests/images/blue.gif delete mode 100644 tests/images/broken.png create mode 100644 tests/images/cats.gif delete mode 100644 tests/images/circle.png delete mode 100644 tests/images/exif.jpg delete mode 100644 tests/images/gradient.png create mode 100644 tests/images/green.gif delete mode 100644 tests/images/iptc.jpg create mode 100644 tests/images/red.gif delete mode 100644 tests/images/star.png delete mode 100644 tests/images/test.jpg delete mode 100755 tests/images/test.webp delete mode 100644 tests/images/trim.png delete mode 100644 tests/tmp/.gitkeep diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 86ddce95..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: php - -sudo: false - -jobs: - include: - - dist: trusty - php: 5.4 - - dist: trusty - php: 5.5 - - dist: xenial - php: 5.6 - - dist: xenial - php: 7.0 - - dist: xenial - php: 7.1 - - dist: xenial - php: 7.2 - - dist: xenial - php: 7.3 - - dist: xenial - php: 7.4 - - dist: xenial - php: nightly - - dist: xenial - php: hhvm - allow_failures: - - php: nightly - - php: hhvm - -before_script: - - printf "\n" | pecl install imagick - - composer self-update || true - - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader - -script: vendor/bin/phpunit diff --git a/LICENSE b/LICENSE deleted file mode 100644 index bc444ba2..00000000 --- a/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Oliver Vogel - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100755 index 350f471c..00000000 --- a/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Intervention Image - -Intervention Image is a **PHP image handling and manipulation** library providing an easier and expressive way to create, edit, and compose images. The package includes ServiceProviders and Facades for easy **Laravel** integration. - -[![Latest Version](https://img.shields.io/packagist/v/intervention/image.svg)](https://packagist.org/packages/intervention/image) -[![Build Status](https://travis-ci.org/Intervention/image.png?branch=master)](https://travis-ci.org/Intervention/image) -[![Monthly Downloads](https://img.shields.io/packagist/dm/intervention/image.svg)](https://packagist.org/packages/intervention/image/stats) - -## Requirements - -- PHP >=5.4 -- Fileinfo Extension - -## Supported Image Libraries - -- GD Library (>=2.0) -- Imagick PHP extension (>=6.5.7) - -## Getting started - -- [Installation](http://image.intervention.io/getting_started/installation) -- [Laravel Framework Integration](http://image.intervention.io/getting_started/installation#laravel) -- [Basic Usage](http://image.intervention.io/use/basics) - -## Code Examples - -```php -// open an image file -$img = Image::make('public/foo.jpg'); - -// resize image instance -$img->resize(320, 240); - -// insert a watermark -$img->insert('public/watermark.png'); - -// save image in desired format -$img->save('public/bar.jpg'); -``` - -Refer to the [official documentation](http://image.intervention.io/) to learn more about Intervention Image. - -## Contributing - -Contributions to the Intervention Image library are welcome. Please note the following guidelines before submitting your pull request. - -- Follow [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standards. -- Write tests for new functions and added features -- API calls should work consistently with both GD and Imagick drivers - -## License - -Intervention Image is licensed under the [MIT License](http://opensource.org/licenses/MIT). - -Copyright 2017 [Oliver Vogel](http://olivervogel.com/) diff --git a/composer.json b/composer.json index e750b406..93776f08 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "intervention/image", - "description": "Image handling and manipulation library with support for Laravel integration", + "description": "PHP image manipulation", "homepage": "http://image.intervention.io/", "keywords": ["image", "gd", "imagick", "laravel", "watermark", "thumbnail"], "license": "MIT", @@ -8,40 +8,25 @@ { "name": "Oliver Vogel", "email": "oliver@olivervogel.com", - "homepage": "http://olivervogel.com/" + "homepage": "http://intervention.io/" } ], "require": { - "php": ">=5.4.0", - "ext-fileinfo": "*", - "guzzlehttp/psr7": "~1.1 || ^2.0" + "php": "^8", + "intervention/gif": "dev-master", + "intervention/mimesniffer": "^0.4.2" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15", - "mockery/mockery": "~0.9.2" - }, - "suggest": { - "ext-gd": "to use GD library based image processing.", - "ext-imagick": "to use Imagick based image processing.", - "intervention/imagecache": "Caching extension for the Intervention Image library" + "phpunit/phpunit": "^9" }, "autoload": { "psr-4": { - "Intervention\\Image\\": "src/Intervention/Image" + "Intervention\\Image\\": "src" } }, - "extra": { - "branch-alias": { - "dev-master": "2.4-dev" - }, - "laravel": { - "providers": [ - "Intervention\\Image\\ImageServiceProvider" - ], - "aliases": { - "Image": "Intervention\\Image\\Facades\\Image" - } + "autoload-dev": { + "psr-4": { + "Intervention\\Image\\Tests\\": "tests" } - }, - "minimum-stability": "stable" + } } diff --git a/phpunit.xml b/phpunit.xml index 3347b75b..422eeac6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" > diff --git a/provides.json b/provides.json deleted file mode 100644 index a8cd1b6a..00000000 --- a/provides.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "providers": [ - "Intervention\\Image\\ImageServiceProvider" - ], - "aliases": [ - { - "alias": "Image", - "facade": "Intervention\\Image\\Facades\\Image" - } - ] -} diff --git a/src/Collection.php b/src/Collection.php new file mode 100644 index 00000000..2c40af19 --- /dev/null +++ b/src/Collection.php @@ -0,0 +1,137 @@ +items); + } + + public function toArray(): array + { + return $this->items; + } + + /** + * Count items in collection + * + * @return integer + */ + public function count(): int + { + return count($this->items); + } + + /** + * Append new item to collection + * + * @param mixed $item + * @return CollectionInterface + */ + public function push($item): CollectionInterface + { + $this->items[] = $item; + + return $this; + } + + /** + * Return first item in collection + * + * @return mixed + */ + public function first() + { + if ($item = reset($this->items)) { + return $item; + } + + return null; + } + + /** + * Returns last item in collection + * + * @return mixed + */ + public function last() + { + if ($item = end($this->items)) { + return $item; + } + + return null; + } + + /** + * Return item with given key + * + * @param integer $key + * @return mixed + */ + public function get(int $key = 0) + { + if (! array_key_exists($key, $this->items)) { + return null; + } + + return $this->items[$key]; + } + + public function map(callable $callback): self + { + $items = array_map(function ($item) use ($callback) { + return $callback($item); + }, $this->items); + + return new self($items); + } + + public function pushEach(array $data, ?callable $callback = null): CollectionInterface + { + if (! is_iterable($data)) { + throw new RuntimeException('Unable to iterate given data.'); + } + + foreach ($data as $item) { + $this->push(is_callable($callback) ? $callback($item) : $item); + } + + return $this; + } +} diff --git a/src/Drivers/Abstract/AbstractColor.php b/src/Drivers/Abstract/AbstractColor.php new file mode 100644 index 00000000..449e4747 --- /dev/null +++ b/src/Drivers/Abstract/AbstractColor.php @@ -0,0 +1,17 @@ +red(), + $this->green(), + $this->blue() + ); + } +} diff --git a/src/Drivers/Abstract/AbstractFrame.php b/src/Drivers/Abstract/AbstractFrame.php new file mode 100644 index 00000000..c83c8af3 --- /dev/null +++ b/src/Drivers/Abstract/AbstractFrame.php @@ -0,0 +1,8 @@ +frames; + } + + public function getFrames(): Collection + { + return $this->frames; + } + + public function addFrame(FrameInterface $frame): ImageInterface + { + $this->frames->push($frame); + + return $this; + } + + public function size(): SizeInterface + { + return new Size($this->width(), $this->height()); + } + + public function isAnimated(): bool + { + return $this->getFrames()->count() > 1; + } + + public function modify(ModifierInterface $modifier): ImageInterface + { + return $modifier->apply($this); + } + + public function encode(EncoderInterface $encoder, ?string $path = null): string + { + $encoded = $encoder->encode($this); + + if ($path) { + $saved = @file_put_contents($path, $encoded); + if ($saved === false) { + throw new NotWritableException( + "Can't write image data to path ({$path})." + ); + } + } + + return $encoded; + } + + public function toJpeg(?int $quality = null, ?string $path = null): string + { + return $this->encode( + $this->resolveDriverClass('Encoders\JpegEncoder', $quality), + $path + ); + } + + public function toGif(?string $path = null): string + { + return $this->encode( + $this->resolveDriverClass('Encoders\GifEncoder'), + $path + ); + } +} diff --git a/src/Drivers/Abstract/AbstractInputHandler.php b/src/Drivers/Abstract/AbstractInputHandler.php new file mode 100644 index 00000000..fce61f85 --- /dev/null +++ b/src/Drivers/Abstract/AbstractInputHandler.php @@ -0,0 +1,17 @@ +chain()->handle($input); + } +} diff --git a/src/Drivers/Abstract/Decoders/AbstractDecoder.php b/src/Drivers/Abstract/Decoders/AbstractDecoder.php new file mode 100644 index 00000000..93740041 --- /dev/null +++ b/src/Drivers/Abstract/Decoders/AbstractDecoder.php @@ -0,0 +1,47 @@ +decode($input); + } catch (DecoderException $e) { + if ($this->hasSuccessor()) { + return $this->successor->handle($input); + } + + $this->fail(); + } + + return $decoded; + } + + protected function hasSuccessor(): bool + { + return $this->successor !== null; + } + + protected function fail(): void + { + throw new DecoderException("Unable to decode given input."); + } + + protected function inputType($input): AbstractType + { + return MimeSniffer::createFromString($input)->getType(); + } +} diff --git a/src/Drivers/Abstract/Encoders/AbstractEncoder.php b/src/Drivers/Abstract/Encoders/AbstractEncoder.php new file mode 100644 index 00000000..31a53ac5 --- /dev/null +++ b/src/Drivers/Abstract/Encoders/AbstractEncoder.php @@ -0,0 +1,41 @@ +quality = $quality; + + return $this; + } + + public function getQuality(): int + { + return $this->quality; + } +} diff --git a/src/Drivers/Gd/Color.php b/src/Drivers/Gd/Color.php new file mode 100644 index 00000000..351072bd --- /dev/null +++ b/src/Drivers/Gd/Color.php @@ -0,0 +1,57 @@ +value = $value; + } + + public function red(): int + { + return $this->toArray()[0]; + } + + public function green(): int + { + return $this->toArray()[1]; + } + + public function blue(): int + { + return $this->toArray()[2]; + } + + public function alpha(): float + { + return $this->toArray()[3]; + } + + public function toArray(): array + { + $a = ($this->value >> 24) & 0xFF; + $r = ($this->value >> 16) & 0xFF; + $g = ($this->value >> 8) & 0xFF; + $b = $this->value & 0xFF; + $a = (float) round(1 - $a / 127, 2); + + return [$r, $g, $b, $a]; + } +} diff --git a/src/Drivers/Gd/Decoders/ArrayColorDecoder.php b/src/Drivers/Gd/Decoders/ArrayColorDecoder.php new file mode 100644 index 00000000..7a1b7161 --- /dev/null +++ b/src/Drivers/Gd/Decoders/ArrayColorDecoder.php @@ -0,0 +1,33 @@ +isValidColorArray($input)) { + $this->fail(); + } + + list($r, $g, $b, $a) = $input; + + return new Color( + ($this->opacityToGdAlpha($a) << 24) + ($r << 16) + ($g << 8) + $b + ); + } + + protected function opacityToGdAlpha(float $opacity): int + { + return intval(round($opacity * 127 * -1 + 127)); + } +} diff --git a/src/Drivers/Gd/Decoders/Base64ImageDecoder.php b/src/Drivers/Gd/Decoders/Base64ImageDecoder.php new file mode 100644 index 00000000..fb22e3ba --- /dev/null +++ b/src/Drivers/Gd/Decoders/Base64ImageDecoder.php @@ -0,0 +1,22 @@ +isValidBase64($input)) { + $this->fail(); + } + + return parent::decode(base64_decode($input)); + } +} diff --git a/src/Drivers/Gd/Decoders/BinaryImageDecoder.php b/src/Drivers/Gd/Decoders/BinaryImageDecoder.php new file mode 100644 index 00000000..a5e69c0b --- /dev/null +++ b/src/Drivers/Gd/Decoders/BinaryImageDecoder.php @@ -0,0 +1,55 @@ +inputType($input)->isBinary()) { + $this->fail(); + } + + if (is_a($this->inputType($input), ImageGif::class)) { + return $this->decodeGif($input); // decode (animated) gif + } + + $resource = @imagecreatefromstring($input); + + if ($resource === false) { + $this->fail(); + } + + return new Image(new Collection([new Frame($resource)])); + } + + protected function decodeGif($input): ImageInterface + { + $image = new Image(new Collection()); + $gif = GifDecoder::decode($input); + + if (!$gif->isAnimated()) { + return $image->addFrame(new Frame(@imagecreatefromstring($input))); + } + + $splitter = GifSplitter::create($gif)->split(); + $delays = $splitter->getDelays(); + foreach ($splitter->coalesceToResources() as $key => $gd) { + $image->addFrame((new Frame($gd))->setDelay($delays[$key])); + } + + return $image; + } +} diff --git a/src/Drivers/Gd/Decoders/DataUriImageDecoder.php b/src/Drivers/Gd/Decoders/DataUriImageDecoder.php new file mode 100644 index 00000000..b1c8f245 --- /dev/null +++ b/src/Drivers/Gd/Decoders/DataUriImageDecoder.php @@ -0,0 +1,33 @@ +fail(); + } + + $uri = $this->decodeDataUri($input); + + if (! $uri->isValid()) { + $this->fail(); + } + + if ($uri->isBase64Encoded()) { + return parent::decode(base64_decode($uri->data())); + } + + return parent::decode(urldecode($uri->data())); + } +} diff --git a/src/Drivers/Gd/Decoders/FilePathImageDecoder.php b/src/Drivers/Gd/Decoders/FilePathImageDecoder.php new file mode 100644 index 00000000..6448a645 --- /dev/null +++ b/src/Drivers/Gd/Decoders/FilePathImageDecoder.php @@ -0,0 +1,28 @@ +fail(); + } + + try { + if (! @is_file($input)) { + $this->fail(); + } + } catch (Exception $e) { + $this->fail(); + } + + return parent::decode(file_get_contents($input)); + } +} diff --git a/src/Drivers/Gd/Encoders/GifEncoder.php b/src/Drivers/Gd/Encoders/GifEncoder.php new file mode 100644 index 00000000..d4a99a02 --- /dev/null +++ b/src/Drivers/Gd/Encoders/GifEncoder.php @@ -0,0 +1,33 @@ +isAnimated()) { + return $this->encodeAnimated($image); + } + + return $this->getBuffered(function () use ($image) { + imagegif($image->getFrames()->first()->getCore()); + }); + } + + protected function encodeAnimated($image): string + { + $builder = GifBuilder::canvas($image->width(), $image->height(), 2); + foreach ($image as $key => $frame) { + $source = $this->encode($frame->toImage()); + $builder->addFrame($source, $frame->getDelay()); + } + + return $builder->encode(); + } +} diff --git a/src/Drivers/Gd/Encoders/JpegEncoder.php b/src/Drivers/Gd/Encoders/JpegEncoder.php new file mode 100644 index 00000000..408c7b95 --- /dev/null +++ b/src/Drivers/Gd/Encoders/JpegEncoder.php @@ -0,0 +1,17 @@ +getBuffered(function () use ($image) { + imagejpeg($image->getFrames()->first()->getCore(), null, $this->quality); + }); + } +} diff --git a/src/Drivers/Gd/Frame.php b/src/Drivers/Gd/Frame.php new file mode 100644 index 00000000..e5c9e0d1 --- /dev/null +++ b/src/Drivers/Gd/Frame.php @@ -0,0 +1,111 @@ +core; + } + + public function getDelay(): int + { + return $this->delay; + } + + public function setDelay(int $delay): FrameInterface + { + $this->delay = $delay; + + return $this; + } + + public function getDispose(): int + { + return $this->dispose; + } + + public function setDispose(int $dispose): FrameInterface + { + $this->dispose = $dispose; + + return $this; + } + + public function setOffset(int $left, int $top): FrameInterface + { + $this->offset_left = $left; + $this->offset_top = $top; + + return $this; + } + + public function getOffsetLeft(): int + { + return $this->offset_left; + } + + public function setOffsetLeft(int $offset): FrameInterface + { + $this->offset_left = $offset; + + return $this; + } + + public function getOffsetTop(): int + { + return $this->offset_top; + } + + public function setOffsetTop(int $offset): FrameInterface + { + $this->offset_top = $offset; + + return $this; + } + + public function toImage(): ImageInterface + { + return new Image(new Collection([$this])); + } +} diff --git a/src/Drivers/Gd/Image.php b/src/Drivers/Gd/Image.php new file mode 100644 index 00000000..40742d24 --- /dev/null +++ b/src/Drivers/Gd/Image.php @@ -0,0 +1,36 @@ +frames->first()->getCore()); + } + + public function height(): int + { + return imagesy($this->frames->first()->getCore()); + } + + public function greyscale(): ImageInterface + { + return $this->modify(new Modifiers\GreyscaleModifier()); + } +} diff --git a/src/Drivers/Gd/ImageFactory.php b/src/Drivers/Gd/ImageFactory.php new file mode 100644 index 00000000..0127f36c --- /dev/null +++ b/src/Drivers/Gd/ImageFactory.php @@ -0,0 +1,19 @@ +getCore(), IMG_FILTER_GRAYSCALE); + } + + return $image; + } +} diff --git a/src/Drivers/Imagick/Color.php b/src/Drivers/Imagick/Color.php new file mode 100644 index 00000000..f07a82ca --- /dev/null +++ b/src/Drivers/Imagick/Color.php @@ -0,0 +1,53 @@ +pixel = $pixel; + } + + public function red(): int + { + return round($this->pixel->getColorValue(Imagick::COLOR_RED) * 255); + } + + public function green(): int + { + return round($this->pixel->getColorValue(Imagick::COLOR_GREEN) * 255); + } + + public function blue(): int + { + return round($this->pixel->getColorValue(Imagick::COLOR_BLUE) * 255); + } + + public function alpha(): float + { + return round($this->pixel->getColorValue(Imagick::COLOR_ALPHA), 2); + } + + public function toArray(): array + { + return [ + $this->red(), + $this->green(), + $this->blue(), + $this->alpha() + ]; + } +} diff --git a/src/Drivers/Imagick/Decoders/ArrayColorDecoder.php b/src/Drivers/Imagick/Decoders/ArrayColorDecoder.php new file mode 100644 index 00000000..e2110744 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/ArrayColorDecoder.php @@ -0,0 +1,31 @@ +isValidColorArray($input)) { + $this->fail(); + } + + list($r, $g, $b, $a) = $input; + + $pixel = new ImagickPixel( + sprintf('rgba(%d, %d, %d, %.2F)', $r, $g, $b, $a) + ); + + return new Color($pixel); + } +} diff --git a/src/Drivers/Imagick/Decoders/Base64ImageDecoder.php b/src/Drivers/Imagick/Decoders/Base64ImageDecoder.php new file mode 100644 index 00000000..46d34430 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/Base64ImageDecoder.php @@ -0,0 +1,22 @@ +isValidBase64($input)) { + $this->fail(); + } + + return parent::decode(base64_decode($input)); + } +} diff --git a/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php b/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php new file mode 100644 index 00000000..96cc9a98 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/BinaryImageDecoder.php @@ -0,0 +1,34 @@ +inputType($input)->isBinary()) { + $this->fail(); + } + + $imagick = new Imagick(); + $imagick->readImageBlob($input); + $imagick = $imagick->coalesceImages(); + + $image = new Image(new Collection()); + + foreach ($imagick as $frame_content) { + $image->addFrame(new Frame($frame_content)); + } + + return $image; + } +} diff --git a/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php b/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php new file mode 100644 index 00000000..9f80b117 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php @@ -0,0 +1,33 @@ +fail(); + } + + $uri = $this->decodeDataUri($input); + + if (! $uri->isValid()) { + $this->fail(); + } + + if ($uri->isBase64Encoded()) { + return parent::decode(base64_decode($uri->data())); + } + + return parent::decode(urldecode($uri->data())); + } +} diff --git a/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php b/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php new file mode 100644 index 00000000..a4fe1d30 --- /dev/null +++ b/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php @@ -0,0 +1,28 @@ +fail(); + } + + try { + if (! @is_file($input)) { + $this->fail(); + } + } catch (Exception $e) { + $this->fail(); + } + + return parent::decode(file_get_contents($input)); + } +} diff --git a/src/Drivers/Imagick/Encoders/GifEncoder.php b/src/Drivers/Imagick/Encoders/GifEncoder.php new file mode 100644 index 00000000..4b62dae2 --- /dev/null +++ b/src/Drivers/Imagick/Encoders/GifEncoder.php @@ -0,0 +1,29 @@ +getFrames() as $frame) { + $gif->addImage($frame->getCore()); + } + + $gif->setFormat($format); + $gif->setImageFormat($format); + $gif->setCompression($compression); + $gif->setImageCompression($compression); + + return $gif->getImagesBlob(); + } +} diff --git a/src/Drivers/Imagick/Encoders/JpegEncoder.php b/src/Drivers/Imagick/Encoders/JpegEncoder.php new file mode 100644 index 00000000..179531d7 --- /dev/null +++ b/src/Drivers/Imagick/Encoders/JpegEncoder.php @@ -0,0 +1,29 @@ +getFrames()->first()->getCore(); + $imagick->setImageBackgroundColor('white'); + $imagick->setBackgroundColor('white'); + $imagick->setFormat($format); + $imagick->setImageFormat($format); + $imagick->setCompression($compression); + $imagick->setImageCompression($compression); + $imagick->setCompressionQuality($this->quality); + $imagick->setImageCompressionQuality($this->quality); + + return $imagick->getImagesBlob(); + } +} diff --git a/src/Drivers/Imagick/Frame.php b/src/Drivers/Imagick/Frame.php new file mode 100644 index 00000000..c5c5652a --- /dev/null +++ b/src/Drivers/Imagick/Frame.php @@ -0,0 +1,83 @@ +core; + } + + public function getDelay(): int + { + return $this->core->getImageDelay(); + } + + public function setDelay(int $delay): FrameInterface + { + $this->core->setImageDelay($delay); + + return $this; + } + + public function getDispose(): int + { + return $this->core->getImageDispose(); + } + + public function setDispose(int $dispose): FrameInterface + { + $this->core->setImageDispose($dispose); + + return $this; + } + + public function setOffset(int $left, int $top): FrameInterface + { + $this->core->setImagePage( + $this->core->getImageWidth(), + $this->core->getImageHeight(), + $left, + $top + ); + + return $this; + } + + public function getOffsetLeft(): int + { + return $this->core->getImagePage()['x']; + } + + public function setOffsetLeft(int $offset): FrameInterface + { + return $this->setOffset($offset, $this->getOffsetTop()); + } + + public function getOffsetTop(): int + { + return $this->core->getImagePage()['y']; + } + + public function setOffsetTop(int $offset): FrameInterface + { + return $this->setOffset($this->getOffsetLeft(), $offset); + } + + public function toImage(): ImageInterface + { + return new Image(new Collection([$this])); + } +} diff --git a/src/Drivers/Imagick/Image.php b/src/Drivers/Imagick/Image.php new file mode 100644 index 00000000..be0a3afc --- /dev/null +++ b/src/Drivers/Imagick/Image.php @@ -0,0 +1,35 @@ +frames->first()->getCore()->getImageWidth(); + } + + public function height(): int + { + return $this->frames->first()->getCore()->getImageHeight(); + } + + public function greyscale(): ImageInterface + { + return $this->modify(new Modifiers\GreyscaleModifier()); + } +} diff --git a/src/Drivers/Imagick/InputHandler.php b/src/Drivers/Imagick/InputHandler.php new file mode 100644 index 00000000..d1fcbde2 --- /dev/null +++ b/src/Drivers/Imagick/InputHandler.php @@ -0,0 +1,22 @@ +image as $frame) { + $frame->getCore()->modulateImage(100, 0, 100); + } + + return $this->image; + } +} diff --git a/src/Exceptions/DecoderException.php b/src/Exceptions/DecoderException.php new file mode 100644 index 00000000..9271e202 --- /dev/null +++ b/src/Exceptions/DecoderException.php @@ -0,0 +1,8 @@ +x = $x; + $this->y = $y; + } + + /** + * Sets X coordinate + * + * @param integer $x + */ + public function setX(int $x): self + { + $this->x = $x; + + return $this; + } + + /** + * Get X coordinate + * + * @return integer + */ + public function getX(): int + { + return $this->x; + } + + /** + * Sets Y coordinate + * + * @param integer $y + */ + public function setY(int $y): self + { + $this->y = $y; + + return $this; + } + + /** + * Get Y coordinate + * + * @return integer + */ + public function getY(): int + { + return $this->y; + } + + /** + * Move X coordinate + * + * @param integer $x + */ + public function moveX(int $value): self + { + $this->x += $value; + + return $this; + } + + /** + * Move Y coordinate + * + * @param integer $y + */ + public function moveY(int $value): self + { + $this->y += $value; + + return $this; + } + + /** + * Sets both X and Y coordinate + * + * @param integer $x + * @param integer $y + * @return Point + */ + public function setPosition(int $x, int $y): self + { + $this->setX($x); + $this->setY($y); + + return $this; + } + + /** + * Rotate point ccw around pivot + * + * @param float $angle + * @param Point $pivot + * @return Point + */ + public function rotate(float $angle, Point $pivot): self + { + $sin = round(sin(deg2rad($angle)), 6); + $cos = round(cos(deg2rad($angle)), 6); + + return $this->setPosition( + $cos * ($this->x - $pivot->x) - $sin * ($this->y - $pivot->y) + $pivot->x, + $sin * ($this->x - $pivot->x) + $cos * ($this->y - $pivot->y) + $pivot->y + ); + } +} diff --git a/src/Geometry/Size.php b/src/Geometry/Size.php new file mode 100644 index 00000000..4f19bc30 --- /dev/null +++ b/src/Geometry/Size.php @@ -0,0 +1,92 @@ +width = $width; + $this->height = $height; + $this->pivot = $pivot ? $pivot : new Point(); + } + + public function getWidth(): int + { + return $this->width; + } + + public function getHeight(): int + { + return $this->height; + } + + /** + * Get current pivot point + * + * @return Point + */ + public function getPivot(): PointInterface + { + return $this->pivot; + } + + public function setWidth(int $width): SizeInterface + { + $this->width = $width; + + return $this; + } + + public function setHeight(int $height): SizeInterface + { + $this->height = $height; + + return $this; + } + + public function getAspectRatio(): float + { + return $this->width / $this->height; + } + + public function fitsInto(SizeInterface $size): bool + { + if ($this->getWidth() > $size->getWidth()) { + return false; + } + + if ($this->getHeight() > $size->getHeight()) { + return false; + } + + return true; + } + + /** + * Determine if size is landscape format + * + * @return boolean + */ + public function isLandscape(): bool + { + return $this->getWidth() > $this->getHeight(); + } + + /** + * Determine if size is portrait format + * + * @return boolean + */ + public function isPortrait(): bool + { + return $this->getWidth() < $this->getHeight(); + } +} diff --git a/src/ImageManager.php b/src/ImageManager.php new file mode 100644 index 00000000..428df54b --- /dev/null +++ b/src/ImageManager.php @@ -0,0 +1,96 @@ + 'gd', + ]; + + /** + * Create new instance + * + * @param array $config + */ + public function __construct(array $config = []) + { + $this->configure($config); + } + + /** + * Override configuration settings + * + * @param array $config + */ + public function configure(array $config = []): self + { + $this->config = array_replace($this->config, $config); + + return $this; + } + + /** + * Return given value of configuration + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function getConfig($key, $default = null) + { + return array_key_exists($key, $this->config) ? $this->config[$key] : $default; + } + + /** + * Create new image instance from scratch + * + * @param int $width + * @param int $height + * @return ImageInterface + */ + public function create(int $width, int $height): ImageInterface + { + return $this->resolve('ImageFactory')->newImage($width, $height); + } + + /** + * Create new image instance from input + * + * @param mixed $input + * @return ImageInterface + */ + public function make($input): ImageInterface + { + return $this->resolve('InputHandler')->handle($input); + } + + /** + * Resolve given classname according to current configuration + * + * @param string $classname + * @param array $arguments + * @return mixed + */ + private function resolve(string $classname, ...$arguments) + { + $classname = sprintf( + "Intervention\\Image\\Drivers\\%s\\%s", + ucfirst($this->config['driver']), + $classname + ); + + $reflection = new ReflectionClass($classname); + + return $reflection->newInstanceArgs($arguments); + } +} diff --git a/src/Interfaces/CollectionInterface.php b/src/Interfaces/CollectionInterface.php new file mode 100644 index 00000000..5c63e5a7 --- /dev/null +++ b/src/Interfaces/CollectionInterface.php @@ -0,0 +1,12 @@ +parse($value); - } - - /** - * Parses given value as color - * - * @param mixed $value - * @return \Intervention\Image\AbstractColor - */ - public function parse($value) - { - switch (true) { - - case is_string($value): - $this->initFromString($value); - break; - - case is_int($value): - $this->initFromInteger($value); - break; - - case is_array($value): - $this->initFromArray($value); - break; - - case is_object($value): - $this->initFromObject($value); - break; - - case is_null($value): - $this->initFromArray([255, 255, 255, 0]); - break; - - default: - throw new NotReadableException( - "Color format ({$value}) cannot be read." - ); - } - - return $this; - } - - /** - * Formats current color instance into given format - * - * @param string $type - * @return mixed - */ - public function format($type) - { - switch (strtolower($type)) { - - case 'rgba': - return $this->getRgba(); - - case 'hex': - return $this->getHex('#'); - - case 'int': - case 'integer': - return $this->getInt(); - - case 'array': - return $this->getArray(); - - case 'obj': - case 'object': - return $this; - - default: - throw new NotSupportedException( - "Color format ({$type}) is not supported." - ); - } - } - - /** - * Reads RGBA values from string into array - * - * @param string $value - * @return array - */ - protected function rgbaFromString($value) - { - $result = false; - - // parse color string in hexidecimal format like #cccccc or cccccc or ccc - $hexPattern = '/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i'; - - // parse color string in format rgb(140, 140, 140) - $rgbPattern = '/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i'; - - // parse color string in format rgba(255, 0, 0, 0.5) - $rgbaPattern = '/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,4})\)$/i'; - - if (preg_match($hexPattern, $value, $matches)) { - $result = []; - $result[0] = strlen($matches[1]) == '1' ? hexdec($matches[1].$matches[1]) : hexdec($matches[1]); - $result[1] = strlen($matches[2]) == '1' ? hexdec($matches[2].$matches[2]) : hexdec($matches[2]); - $result[2] = strlen($matches[3]) == '1' ? hexdec($matches[3].$matches[3]) : hexdec($matches[3]); - $result[3] = 1; - } elseif (preg_match($rgbPattern, $value, $matches)) { - $result = []; - $result[0] = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0; - $result[1] = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0; - $result[2] = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0; - $result[3] = 1; - } elseif (preg_match($rgbaPattern, $value, $matches)) { - $result = []; - $result[0] = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0; - $result[1] = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0; - $result[2] = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0; - $result[3] = ($matches[4] >= 0 && $matches[4] <= 1) ? $matches[4] : 0; - } else { - throw new NotReadableException( - "Unable to read color ({$value})." - ); - } - - return $result; - } -} diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php deleted file mode 100644 index 743cc5c3..00000000 --- a/src/Intervention/Image/AbstractDecoder.php +++ /dev/null @@ -1,364 +0,0 @@ -data = $data; - } - - /** - * Init from given URL - * - * @param string $url - * @return \Intervention\Image\Image - */ - public function initFromUrl($url) - { - - $options = [ - 'http' => [ - 'method'=>"GET", - 'protocol_version'=>1.1, // force use HTTP 1.1 for service mesh environment with envoy - 'header'=>"Accept-language: en\r\n". - "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n" - ] - ]; - - $context = stream_context_create($options); - - - if ($data = @file_get_contents($url, false, $context)) { - return $this->initFromBinary($data); - } - - throw new NotReadableException( - "Unable to init from given url (".$url.")." - ); - } - - /** - * Init from given stream - * - * @param StreamInterface|resource $stream - * @return \Intervention\Image\Image - */ - public function initFromStream($stream) - { - if (!$stream instanceof StreamInterface) { - $stream = new Stream($stream); - } - - try { - $offset = $stream->tell(); - } catch (\RuntimeException $e) { - $offset = 0; - } - - $shouldAndCanSeek = $offset !== 0 && $stream->isSeekable(); - - if ($shouldAndCanSeek) { - $stream->rewind(); - } - - try { - $data = $stream->getContents(); - } catch (\RuntimeException $e) { - $data = null; - } - - if ($shouldAndCanSeek) { - $stream->seek($offset); - } - - if ($data) { - return $this->initFromBinary($data); - } - - throw new NotReadableException( - "Unable to init from given stream" - ); - } - - /** - * Determines if current source data is GD resource - * - * @return boolean - */ - public function isGdResource() - { - if (is_resource($this->data)) { - return (get_resource_type($this->data) == 'gd'); - } - - if ($this->data instanceof \GdImage) { - return true; - } - - return false; - } - - /** - * Determines if current source data is Imagick object - * - * @return boolean - */ - public function isImagick() - { - return is_a($this->data, 'Imagick'); - } - - /** - * Determines if current source data is Intervention\Image\Image object - * - * @return boolean - */ - public function isInterventionImage() - { - return is_a($this->data, '\Intervention\Image\Image'); - } - - /** - * Determines if current data is SplFileInfo object - * - * @return boolean - */ - public function isSplFileInfo() - { - return is_a($this->data, 'SplFileInfo'); - } - - /** - * Determines if current data is Symfony UploadedFile component - * - * @return boolean - */ - public function isSymfonyUpload() - { - return is_a($this->data, 'Symfony\Component\HttpFoundation\File\UploadedFile'); - } - - /** - * Determines if current source data is file path - * - * @return boolean - */ - public function isFilePath() - { - if (is_string($this->data)) { - try { - return is_file($this->data); - } catch (\Exception $e) { - return false; - } - } - - return false; - } - - /** - * Determines if current source data is url - * - * @return boolean - */ - public function isUrl() - { - return (bool) filter_var($this->data, FILTER_VALIDATE_URL); - } - - /** - * Determines if current source data is a stream resource - * - * @return boolean - */ - public function isStream() - { - if ($this->data instanceof StreamInterface) return true; - if (!is_resource($this->data)) return false; - if (get_resource_type($this->data) !== 'stream') return false; - - return true; - } - - /** - * Determines if current source data is binary data - * - * @return boolean - */ - public function isBinary() - { - if (is_string($this->data)) { - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $this->data); - return (substr($mime, 0, 4) != 'text' && $mime != 'application/x-empty'); - } - - return false; - } - - /** - * Determines if current source data is data-url - * - * @return boolean - */ - public function isDataUrl() - { - $data = $this->decodeDataUrl($this->data); - - return is_null($data) ? false : true; - } - - /** - * Determines if current source data is base64 encoded - * - * @return boolean - */ - public function isBase64() - { - if (!is_string($this->data)) { - return false; - } - - return base64_encode(base64_decode($this->data)) === str_replace(["\n", "\r"], '', $this->data); - } - - /** - * Initiates new Image from Intervention\Image\Image - * - * @param Image $object - * @return \Intervention\Image\Image - */ - public function initFromInterventionImage($object) - { - return $object; - } - - /** - * Parses and decodes binary image data from data-url - * - * @param string $data_url - * @return string - */ - private function decodeDataUrl($data_url) - { - if (!is_string($data_url)) { - return null; - } - - $pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P.+)$/"; - preg_match($pattern, str_replace(["\n", "\r"], '', $data_url), $matches); - - if (is_array($matches) && array_key_exists('data', $matches)) { - return base64_decode($matches['data']); - } - - return null; - } - - /** - * Initiates new image from mixed data - * - * @param mixed $data - * @return \Intervention\Image\Image - */ - public function init($data) - { - $this->data = $data; - - switch (true) { - - case $this->isGdResource(): - return $this->initFromGdResource($this->data); - - case $this->isImagick(): - return $this->initFromImagick($this->data); - - case $this->isInterventionImage(): - return $this->initFromInterventionImage($this->data); - - case $this->isSplFileInfo(): - return $this->initFromPath($this->data->getRealPath()); - - case $this->isBinary(): - return $this->initFromBinary($this->data); - - case $this->isUrl(): - return $this->initFromUrl($this->data); - - case $this->isStream(): - return $this->initFromStream($this->data); - - case $this->isDataUrl(): - return $this->initFromBinary($this->decodeDataUrl($this->data)); - - case $this->isFilePath(): - return $this->initFromPath($this->data); - - // isBase64 has to be after isFilePath to prevent false positives - case $this->isBase64(): - return $this->initFromBinary(base64_decode($this->data)); - - default: - throw new NotReadableException("Image source not readable"); - } - } - - /** - * Decoder object transforms to string source data - * - * @return string - */ - public function __toString() - { - return (string) $this->data; - } -} diff --git a/src/Intervention/Image/AbstractDriver.php b/src/Intervention/Image/AbstractDriver.php deleted file mode 100644 index 6c591a79..00000000 --- a/src/Intervention/Image/AbstractDriver.php +++ /dev/null @@ -1,140 +0,0 @@ -decoder->init($data); - } - - /** - * Encodes given image - * - * @param Image $image - * @param string $format - * @param int $quality - * @return \Intervention\Image\Image - */ - public function encode($image, $format, $quality) - { - return $this->encoder->process($image, $format, $quality); - } - - /** - * Executes named command on given image - * - * @param Image $image - * @param string $name - * @param array $arguments - * @return \Intervention\Image\Commands\AbstractCommand - */ - public function executeCommand($image, $name, $arguments) - { - $commandName = $this->getCommandClassName($name); - $command = new $commandName($arguments); - $command->execute($image); - - return $command; - } - - /** - * Returns classname of given command name - * - * @param string $name - * @return string - */ - private function getCommandClassName($name) - { - if (extension_loaded('mbstring')) { - $name = mb_strtoupper(mb_substr($name, 0, 1)) . mb_substr($name, 1); - } else { - $name = strtoupper(substr($name, 0, 1)) . substr($name, 1); - } - - $drivername = $this->getDriverName(); - $classnameLocal = sprintf('\Intervention\Image\%s\Commands\%sCommand', $drivername, ucfirst($name)); - $classnameGlobal = sprintf('\Intervention\Image\Commands\%sCommand', ucfirst($name)); - - if (class_exists($classnameLocal)) { - return $classnameLocal; - } elseif (class_exists($classnameGlobal)) { - return $classnameGlobal; - } - - throw new NotSupportedException( - "Command ({$name}) is not available for driver ({$drivername})." - ); - } - - /** - * Returns name of current driver instance - * - * @return string - */ - public function getDriverName() - { - $reflect = new \ReflectionClass($this); - $namespace = $reflect->getNamespaceName(); - - return substr(strrchr($namespace, "\\"), 1); - } -} diff --git a/src/Intervention/Image/AbstractEncoder.php b/src/Intervention/Image/AbstractEncoder.php deleted file mode 100644 index c25f8bff..00000000 --- a/src/Intervention/Image/AbstractEncoder.php +++ /dev/null @@ -1,271 +0,0 @@ -setImage($image); - $this->setFormat($format); - $this->setQuality($quality); - - switch (strtolower($this->format)) { - - case 'data-url': - $this->result = $this->processDataUrl(); - break; - - case 'gif': - case 'image/gif': - $this->result = $this->processGif(); - break; - - case 'png': - case 'image/png': - case 'image/x-png': - $this->result = $this->processPng(); - break; - - case 'jpg': - case 'jpeg': - case 'jfif': - case 'image/jp2': - case 'image/jpg': - case 'image/jpeg': - case 'image/pjpeg': - case 'image/jfif': - $this->result = $this->processJpeg(); - break; - - case 'tif': - case 'tiff': - case 'image/tiff': - case 'image/tif': - case 'image/x-tif': - case 'image/x-tiff': - $this->result = $this->processTiff(); - break; - - case 'bmp': - case 'ms-bmp': - case 'x-bitmap': - case 'x-bmp': - case 'x-ms-bmp': - case 'x-win-bitmap': - case 'x-windows-bmp': - case 'x-xbitmap': - case 'image/ms-bmp': - case 'image/x-bitmap': - case 'image/x-bmp': - case 'image/x-ms-bmp': - case 'image/x-win-bitmap': - case 'image/x-windows-bmp': - case 'image/x-xbitmap': - $this->result = $this->processBmp(); - break; - - case 'ico': - case 'image/x-ico': - case 'image/x-icon': - case 'image/vnd.microsoft.icon': - $this->result = $this->processIco(); - break; - - case 'psd': - case 'image/vnd.adobe.photoshop': - $this->result = $this->processPsd(); - break; - - case 'webp': - case 'image/webp': - case 'image/x-webp': - $this->result = $this->processWebp(); - break; - - case 'avif': - case 'image/avif': - $this->result = $this->processAvif(); - break; - - case 'heic': - case 'image/heic': - case 'image/heif': - $this->result = $this->processHeic(); - break; - - default: - throw new NotSupportedException( - "Encoding format ({$this->format}) is not supported." - ); - } - - $this->setImage(null); - - return $image->setEncoded($this->result); - } - - /** - * Processes and returns encoded image as data-url string - * - * @return string - */ - protected function processDataUrl() - { - $mime = $this->image->mime ? $this->image->mime : 'image/png'; - - return sprintf('data:%s;base64,%s', - $mime, - base64_encode($this->process($this->image, $mime, $this->quality)) - ); - } - - /** - * Sets image to process - * - * @param Image $image - */ - protected function setImage($image) - { - $this->image = $image; - } - - /** - * Determines output format - * - * @param string $format - */ - protected function setFormat($format = null) - { - if ($format == '' && $this->image instanceof Image) { - $format = $this->image->mime; - } - - $this->format = $format ? $format : 'jpg'; - - return $this; - } - - /** - * Determines output quality - * - * @param int $quality - */ - protected function setQuality($quality) - { - $quality = is_null($quality) ? 90 : $quality; - $quality = $quality === 0 ? 1 : $quality; - - if ($quality < 0 || $quality > 100) { - throw new InvalidArgumentException( - 'Quality must range from 0 to 100.' - ); - } - - $this->quality = intval($quality); - - return $this; - } -} diff --git a/src/Intervention/Image/AbstractFont.php b/src/Intervention/Image/AbstractFont.php deleted file mode 100644 index 35c1825a..00000000 --- a/src/Intervention/Image/AbstractFont.php +++ /dev/null @@ -1,295 +0,0 @@ -text = $text; - } - - /** - * Set text to be written - * - * @param String $text - * @return self - */ - public function text($text) - { - $this->text = $text; - - return $this; - } - - /** - * Get text to be written - * - * @return String - */ - public function getText() - { - return $this->text; - } - - /** - * Set font size in pixels - * - * @param int $size - * @return self - */ - public function size($size) - { - $this->size = $size; - - return $this; - } - - /** - * Get font size in pixels - * - * @return int - */ - public function getSize() - { - return $this->size; - } - - /** - * Set color of text to be written - * - * @param mixed $color - * @return self - */ - public function color($color) - { - $this->color = $color; - - return $this; - } - - /** - * Get color of text - * - * @return mixed - */ - public function getColor() - { - return $this->color; - } - - /** - * Set rotation angle of text - * - * @param int $angle - * @return self - */ - public function angle($angle) - { - $this->angle = $angle; - - return $this; - } - - /** - * Get rotation angle of text - * - * @return int - */ - public function getAngle() - { - return $this->angle; - } - - /** - * Set horizontal text alignment - * - * @param string $align - * @return self - */ - public function align($align) - { - $this->align = $align; - - return $this; - } - - /** - * Get horizontal text alignment - * - * @return string - */ - public function getAlign() - { - return $this->align; - } - - /** - * Set vertical text alignment - * - * @param string $valign - * @return self - */ - public function valign($valign) - { - $this->valign = $valign; - - return $this; - } - - /** - * Get vertical text alignment - * - * @return string - */ - public function getValign() - { - return $this->valign; - } - - /** - * Set text kerning - * - * @param string $kerning - * @return void - */ - public function kerning($kerning) - { - $this->kerning = $kerning; - } - - /** - * Get kerning - * - * @return float - */ - public function getKerning() - { - return $this->kerning; - } - - /** - * Set path to font file - * - * @param string $file - * @return self - */ - public function file($file) - { - $this->file = $file; - - return $this; - } - - /** - * Get path to font file - * - * @return string - */ - public function getFile() - { - return $this->file; - } - - /** - * Checks if current font has access to an applicable font file - * - * @return boolean - */ - protected function hasApplicableFontFile() - { - if (is_string($this->file)) { - return file_exists($this->file); - } - - return false; - } - - /** - * Counts lines of text to be written - * - * @return int - */ - public function countLines() - { - return count(explode(PHP_EOL, $this->text)); - } -} diff --git a/src/Intervention/Image/AbstractShape.php b/src/Intervention/Image/AbstractShape.php deleted file mode 100644 index cd4a9f1c..00000000 --- a/src/Intervention/Image/AbstractShape.php +++ /dev/null @@ -1,71 +0,0 @@ -background = $color; - } - - /** - * Set border width and color of current shape - * - * @param int $width - * @param string $color - * @return void - */ - public function border($width, $color = null) - { - $this->border_width = is_numeric($width) ? intval($width) : 0; - $this->border_color = is_null($color) ? '#000000' : $color; - } - - /** - * Determines if current shape has border - * - * @return boolean - */ - public function hasBorder() - { - return ($this->border_width >= 1); - } -} diff --git a/src/Intervention/Image/Commands/AbstractCommand.php b/src/Intervention/Image/Commands/AbstractCommand.php deleted file mode 100644 index e31078ce..00000000 --- a/src/Intervention/Image/Commands/AbstractCommand.php +++ /dev/null @@ -1,81 +0,0 @@ -arguments = $arguments; - } - - /** - * Creates new argument instance from given argument key - * - * @param int $key - * @return \Intervention\Image\Commands\Argument - */ - public function argument($key) - { - return new Argument($this, $key); - } - - /** - * Returns output data of current command - * - * @return mixed - */ - public function getOutput() - { - return $this->output ? $this->output : null; - } - - /** - * Determines if current instance has output data - * - * @return boolean - */ - public function hasOutput() - { - return ! is_null($this->output); - } - - /** - * Sets output data of current command - * - * @param mixed $value - */ - public function setOutput($value) - { - $this->output = $value; - } -} diff --git a/src/Intervention/Image/Commands/Argument.php b/src/Intervention/Image/Commands/Argument.php deleted file mode 100644 index 9538199f..00000000 --- a/src/Intervention/Image/Commands/Argument.php +++ /dev/null @@ -1,225 +0,0 @@ -command = $command; - $this->key = $key; - } - - /** - * Returns name of current arguments command - * - * @return string - */ - public function getCommandName() - { - preg_match("/\\\\([\w]+)Command$/", get_class($this->command), $matches); - return isset($matches[1]) ? lcfirst($matches[1]).'()' : 'Method'; - } - - /** - * Returns value of current argument - * - * @param mixed $default - * @return mixed - */ - public function value($default = null) - { - $arguments = $this->command->arguments; - - if (is_array($arguments)) { - return isset($arguments[$this->key]) ? $arguments[$this->key] : $default; - } - - return $default; - } - - /** - * Defines current argument as required - * - * @return \Intervention\Image\Commands\Argument - */ - public function required() - { - if ( ! array_key_exists($this->key, $this->command->arguments)) { - throw new InvalidArgumentException( - sprintf("Missing argument %d for %s", $this->key + 1, $this->getCommandName()) - ); - } - - return $this; - } - - /** - * Determines that current argument must be of given type - * - * @return \Intervention\Image\Commands\Argument - */ - public function type($type) - { - $valid = true; - $value = $this->value(); - - if ($value === null) { - return $this; - } - - switch (strtolower($type)) { - case 'bool': - case 'boolean': - $valid = \is_bool($value); - $message = '%s accepts only boolean values as argument %d.'; - break; - case 'int': - case 'integer': - $valid = \is_int($value); - $message = '%s accepts only integer values as argument %d.'; - break; - case 'num': - case 'numeric': - $valid = is_numeric($value); - $message = '%s accepts only numeric values as argument %d.'; - break; - case 'str': - case 'string': - $valid = \is_string($value); - $message = '%s accepts only string values as argument %d.'; - break; - case 'array': - $valid = \is_array($value); - $message = '%s accepts only array as argument %d.'; - break; - case 'closure': - $valid = is_a($value, '\Closure'); - $message = '%s accepts only Closure as argument %d.'; - break; - case 'digit': - $valid = $this->isDigit($value); - $message = '%s accepts only integer values as argument %d.'; - break; - } - - if (! $valid) { - $commandName = $this->getCommandName(); - $argument = $this->key + 1; - - if (isset($message)) { - $message = sprintf($message, $commandName, $argument); - } else { - $message = sprintf('Missing argument for %d.', $argument); - } - - throw new InvalidArgumentException( - $message - ); - } - - return $this; - } - - /** - * Determines that current argument value must be numeric between given values - * - * @return \Intervention\Image\Commands\Argument - */ - public function between($x, $y) - { - $value = $this->type('numeric')->value(); - - if (is_null($value)) { - return $this; - } - - $alpha = min($x, $y); - $omega = max($x, $y); - - if ($value < $alpha || $value > $omega) { - throw new InvalidArgumentException( - sprintf('Argument %d must be between %s and %s.', $this->key, $x, $y) - ); - } - - return $this; - } - - /** - * Determines that current argument must be over a minimum value - * - * @return \Intervention\Image\Commands\Argument - */ - public function min($value) - { - $v = $this->type('numeric')->value(); - - if (is_null($v)) { - return $this; - } - - if ($v < $value) { - throw new InvalidArgumentException( - sprintf('Argument %d must be at least %s.', $this->key, $value) - ); - } - - return $this; - } - - /** - * Determines that current argument must be under a maxiumum value - * - * @return \Intervention\Image\Commands\Argument - */ - public function max($value) - { - $v = $this->type('numeric')->value(); - - if (is_null($v)) { - return $this; - } - - if ($v > $value) { - throw new InvalidArgumentException( - sprintf('Argument %d may not be greater than %s.', $this->key, $value) - ); - } - - return $this; - } - - /** - * Checks if value is "PHP" integer (120 but also 120.0) - * - * @param mixed $value - * @return boolean - */ - private function isDigit($value) - { - return is_numeric($value) ? intval($value) == $value : false; - } -} diff --git a/src/Intervention/Image/Commands/ChecksumCommand.php b/src/Intervention/Image/Commands/ChecksumCommand.php deleted file mode 100644 index 9acc4030..00000000 --- a/src/Intervention/Image/Commands/ChecksumCommand.php +++ /dev/null @@ -1,29 +0,0 @@ -getSize(); - - for ($x=0; $x <= ($size->width-1); $x++) { - for ($y=0; $y <= ($size->height-1); $y++) { - $colors[] = $image->pickColor($x, $y, 'array'); - } - } - - $this->setOutput(md5(serialize($colors))); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/CircleCommand.php b/src/Intervention/Image/Commands/CircleCommand.php deleted file mode 100644 index c627818e..00000000 --- a/src/Intervention/Image/Commands/CircleCommand.php +++ /dev/null @@ -1,35 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $x = $this->argument(1)->type('numeric')->required()->value(); - $y = $this->argument(2)->type('numeric')->required()->value(); - $callback = $this->argument(3)->type('closure')->value(); - - $circle_classname = sprintf('\Intervention\Image\%s\Shapes\CircleShape', - $image->getDriver()->getDriverName()); - - $circle = new $circle_classname($diameter); - - if ($callback instanceof Closure) { - $callback($circle); - } - - $circle->applyToImage($image, $x, $y); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/EllipseCommand.php b/src/Intervention/Image/Commands/EllipseCommand.php deleted file mode 100644 index 4637e020..00000000 --- a/src/Intervention/Image/Commands/EllipseCommand.php +++ /dev/null @@ -1,36 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $height = $this->argument(1)->type('numeric')->required()->value(); - $x = $this->argument(2)->type('numeric')->required()->value(); - $y = $this->argument(3)->type('numeric')->required()->value(); - $callback = $this->argument(4)->type('closure')->value(); - - $ellipse_classname = sprintf('\Intervention\Image\%s\Shapes\EllipseShape', - $image->getDriver()->getDriverName()); - - $ellipse = new $ellipse_classname($width, $height); - - if ($callback instanceof Closure) { - $callback($ellipse); - } - - $ellipse->applyToImage($image, $x, $y); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/ExifCommand.php b/src/Intervention/Image/Commands/ExifCommand.php deleted file mode 100644 index 063df6ef..00000000 --- a/src/Intervention/Image/Commands/ExifCommand.php +++ /dev/null @@ -1,61 +0,0 @@ -argument(0)->value(); - - // try to read exif data from image file - try { - if ($image->dirname && $image->basename) { - $stream = $image->dirname . '/' . $image->basename; - } elseif (version_compare(PHP_VERSION, '7.2.0', '>=')) { - // https://www.php.net/manual/en/function.exif-read-data.php#refsect1-function.exif-read-data-changelog - $stream = $image->stream()->detach(); - } else { - // https://bugs.php.net/bug.php?id=65187 - $stream = $image->encode('data-url')->encoded; - } - - $data = @exif_read_data($stream); - - if (!is_null($key) && is_array($data)) { - $data = array_key_exists($key, $data) ? $data[$key] : false; - } - - } catch (\Exception $e) { - throw new NotReadableException( - sprintf( - "Cannot read the Exif data from the filename (%s) provided ", - $image->dirname . '/' . $image->basename - ), - $e->getCode(), - $e - ); - } - - $this->setOutput($data); - return true; - } -} diff --git a/src/Intervention/Image/Commands/IptcCommand.php b/src/Intervention/Image/Commands/IptcCommand.php deleted file mode 100644 index b78a2a8e..00000000 --- a/src/Intervention/Image/Commands/IptcCommand.php +++ /dev/null @@ -1,68 +0,0 @@ -argument(0)->value(); - - $info = []; - @getimagesize($image->dirname .'/'. $image->basename, $info); - - $data = []; - - if (array_key_exists('APP13', $info)) { - $iptc = iptcparse($info['APP13']); - - if (is_array($iptc)) { - $data['DocumentTitle'] = isset($iptc["2#005"][0]) ? $iptc["2#005"][0] : null; - $data['Urgency'] = isset($iptc["2#010"][0]) ? $iptc["2#010"][0] : null; - $data['Category'] = isset($iptc["2#015"][0]) ? $iptc["2#015"][0] : null; - $data['Subcategories'] = isset($iptc["2#020"][0]) ? $iptc["2#020"][0] : null; - $data['Keywords'] = isset($iptc["2#025"][0]) ? $iptc["2#025"] : null; - $data['ReleaseDate'] = isset($iptc["2#030"][0]) ? $iptc["2#030"][0] : null; - $data['ReleaseTime'] = isset($iptc["2#035"][0]) ? $iptc["2#035"][0] : null; - $data['SpecialInstructions'] = isset($iptc["2#040"][0]) ? $iptc["2#040"][0] : null; - $data['CreationDate'] = isset($iptc["2#055"][0]) ? $iptc["2#055"][0] : null; - $data['CreationTime'] = isset($iptc["2#060"][0]) ? $iptc["2#060"][0] : null; - $data['AuthorByline'] = isset($iptc["2#080"][0]) ? $iptc["2#080"][0] : null; - $data['AuthorTitle'] = isset($iptc["2#085"][0]) ? $iptc["2#085"][0] : null; - $data['City'] = isset($iptc["2#090"][0]) ? $iptc["2#090"][0] : null; - $data['SubLocation'] = isset($iptc["2#092"][0]) ? $iptc["2#092"][0] : null; - $data['State'] = isset($iptc["2#095"][0]) ? $iptc["2#095"][0] : null; - $data['Country'] = isset($iptc["2#101"][0]) ? $iptc["2#101"][0] : null; - $data['OTR'] = isset($iptc["2#103"][0]) ? $iptc["2#103"][0] : null; - $data['Headline'] = isset($iptc["2#105"][0]) ? $iptc["2#105"][0] : null; - $data['Source'] = isset($iptc["2#110"][0]) ? $iptc["2#110"][0] : null; - $data['PhotoSource'] = isset($iptc["2#115"][0]) ? $iptc["2#115"][0] : null; - $data['Copyright'] = isset($iptc["2#116"][0]) ? $iptc["2#116"][0] : null; - $data['Caption'] = isset($iptc["2#120"][0]) ? $iptc["2#120"][0] : null; - $data['CaptionWriter'] = isset($iptc["2#122"][0]) ? $iptc["2#122"][0] : null; - } - } - - if (! is_null($key) && is_array($data)) { - $data = array_key_exists($key, $data) ? $data[$key] : false; - } - - $this->setOutput($data); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/LineCommand.php b/src/Intervention/Image/Commands/LineCommand.php deleted file mode 100644 index a068c662..00000000 --- a/src/Intervention/Image/Commands/LineCommand.php +++ /dev/null @@ -1,36 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $y1 = $this->argument(1)->type('numeric')->required()->value(); - $x2 = $this->argument(2)->type('numeric')->required()->value(); - $y2 = $this->argument(3)->type('numeric')->required()->value(); - $callback = $this->argument(4)->type('closure')->value(); - - $line_classname = sprintf('\Intervention\Image\%s\Shapes\LineShape', - $image->getDriver()->getDriverName()); - - $line = new $line_classname($x2, $y2); - - if ($callback instanceof Closure) { - $callback($line); - } - - $line->applyToImage($image, $x1, $y1); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/OrientateCommand.php b/src/Intervention/Image/Commands/OrientateCommand.php deleted file mode 100644 index 552482cb..00000000 --- a/src/Intervention/Image/Commands/OrientateCommand.php +++ /dev/null @@ -1,48 +0,0 @@ -exif('Orientation')) { - - case 2: - $image->flip(); - break; - - case 3: - $image->rotate(180); - break; - - case 4: - $image->rotate(180)->flip(); - break; - - case 5: - $image->rotate(270)->flip(); - break; - - case 6: - $image->rotate(270); - break; - - case 7: - $image->rotate(90)->flip(); - break; - - case 8: - $image->rotate(90); - break; - } - - return true; - } -} diff --git a/src/Intervention/Image/Commands/PolygonCommand.php b/src/Intervention/Image/Commands/PolygonCommand.php deleted file mode 100644 index a2fa9978..00000000 --- a/src/Intervention/Image/Commands/PolygonCommand.php +++ /dev/null @@ -1,49 +0,0 @@ -argument(0)->type('array')->required()->value(); - $callback = $this->argument(1)->type('closure')->value(); - - $vertices_count = count($points); - - // check if number if coordinates is even - if ($vertices_count % 2 !== 0) { - throw new InvalidArgumentException( - "The number of given polygon vertices must be even." - ); - } - - if ($vertices_count < 6) { - throw new InvalidArgumentException( - "You must have at least 3 points in your array." - ); - } - - $polygon_classname = sprintf('\Intervention\Image\%s\Shapes\PolygonShape', - $image->getDriver()->getDriverName()); - - $polygon = new $polygon_classname($points); - - if ($callback instanceof Closure) { - $callback($polygon); - } - - $polygon->applyToImage($image); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/PsrResponseCommand.php b/src/Intervention/Image/Commands/PsrResponseCommand.php deleted file mode 100644 index d75cd903..00000000 --- a/src/Intervention/Image/Commands/PsrResponseCommand.php +++ /dev/null @@ -1,45 +0,0 @@ -argument(0)->value(); - $quality = $this->argument(1)->between(0, 100)->value(); - - //Encoded property will be populated at this moment - $stream = $image->stream($format, $quality); - - $mimetype = finfo_buffer( - finfo_open(FILEINFO_MIME_TYPE), - $image->getEncoded() - ); - - $this->setOutput(new Response( - 200, - [ - 'Content-Type' => $mimetype, - 'Content-Length' => strlen($image->getEncoded()) - ], - $stream - )); - - return true; - } -} \ No newline at end of file diff --git a/src/Intervention/Image/Commands/RectangleCommand.php b/src/Intervention/Image/Commands/RectangleCommand.php deleted file mode 100644 index 24378b38..00000000 --- a/src/Intervention/Image/Commands/RectangleCommand.php +++ /dev/null @@ -1,36 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $y1 = $this->argument(1)->type('numeric')->required()->value(); - $x2 = $this->argument(2)->type('numeric')->required()->value(); - $y2 = $this->argument(3)->type('numeric')->required()->value(); - $callback = $this->argument(4)->type('closure')->value(); - - $rectangle_classname = sprintf('\Intervention\Image\%s\Shapes\RectangleShape', - $image->getDriver()->getDriverName()); - - $rectangle = new $rectangle_classname($x1, $y1, $x2, $y2); - - if ($callback instanceof Closure) { - $callback($rectangle); - } - - $rectangle->applyToImage($image, $x1, $y1); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/ResponseCommand.php b/src/Intervention/Image/Commands/ResponseCommand.php deleted file mode 100644 index 7903b5af..00000000 --- a/src/Intervention/Image/Commands/ResponseCommand.php +++ /dev/null @@ -1,26 +0,0 @@ -argument(0)->value(); - $quality = $this->argument(1)->between(0, 100)->value(); - - $response = new Response($image, $format, $quality); - - $this->setOutput($response->make()); - - return true; - } -} diff --git a/src/Intervention/Image/Commands/StreamCommand.php b/src/Intervention/Image/Commands/StreamCommand.php deleted file mode 100644 index bc2ff9ef..00000000 --- a/src/Intervention/Image/Commands/StreamCommand.php +++ /dev/null @@ -1,39 +0,0 @@ -argument(0)->value(); - $quality = $this->argument(1)->between(0, 100)->value(); - $data = $image->encode($format, $quality)->getEncoded(); - - $this->setOutput($this->getStream($data)); - - return true; - } - - /** - * Create stream from given data - * - * @param string $data - * @return \Psr\Http\Message\StreamInterface - */ - protected function getStream($data) - { - if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { - return \GuzzleHttp\Psr7\Utils::streamFor($data); // guzzlehttp/psr7 >= 2.0 - } - - return \GuzzleHttp\Psr7\stream_for($data); // guzzlehttp/psr7 < 2.0 - } -} diff --git a/src/Intervention/Image/Commands/TextCommand.php b/src/Intervention/Image/Commands/TextCommand.php deleted file mode 100644 index 3c60b4e7..00000000 --- a/src/Intervention/Image/Commands/TextCommand.php +++ /dev/null @@ -1,34 +0,0 @@ -argument(0)->required()->value(); - $x = $this->argument(1)->type('numeric')->value(0); - $y = $this->argument(2)->type('numeric')->value(0); - $callback = $this->argument(3)->type('closure')->value(); - - $fontclassname = sprintf('\Intervention\Image\%s\Font', - $image->getDriver()->getDriverName()); - - $font = new $fontclassname($text); - - if ($callback instanceof Closure) { - $callback($font); - } - - $font->applyToImage($image, $x, $y); - - return true; - } -} diff --git a/src/Intervention/Image/Constraint.php b/src/Intervention/Image/Constraint.php deleted file mode 100644 index 44bdd67a..00000000 --- a/src/Intervention/Image/Constraint.php +++ /dev/null @@ -1,92 +0,0 @@ -size = $size; - } - - /** - * Returns current size of constraint - * - * @return \Intervention\Image\Size - */ - public function getSize() - { - return $this->size; - } - - /** - * Fix the given argument in current constraint - * - * @param int $type - * @return void - */ - public function fix($type) - { - $this->fixed = ($this->fixed & ~(1 << $type)) | (1 << $type); - } - - /** - * Checks if given argument is fixed in current constraint - * - * @param int $type - * @return boolean - */ - public function isFixed($type) - { - return (bool) ($this->fixed & (1 << $type)); - } - - /** - * Fixes aspect ratio in current constraint - * - * @return void - */ - public function aspectRatio() - { - $this->fix(self::ASPECTRATIO); - } - - /** - * Fixes possibility to size up in current constraint - * - * @return void - */ - public function upsize() - { - $this->fix(self::UPSIZE); - } -} diff --git a/src/Intervention/Image/Exception/ImageException.php b/src/Intervention/Image/Exception/ImageException.php deleted file mode 100644 index 83e6b91f..00000000 --- a/src/Intervention/Image/Exception/ImageException.php +++ /dev/null @@ -1,8 +0,0 @@ -dirname = array_key_exists('dirname', $info) ? $info['dirname'] : null; - $this->basename = array_key_exists('basename', $info) ? $info['basename'] : null; - $this->extension = array_key_exists('extension', $info) ? $info['extension'] : null; - $this->filename = array_key_exists('filename', $info) ? $info['filename'] : null; - - if (file_exists($path) && is_file($path)) { - $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); - } - - return $this; - } - - /** - * Get file size - * - * @return mixed - */ - public function filesize() - { - $path = $this->basePath(); - - if (file_exists($path) && is_file($path)) { - return filesize($path); - } - - return false; - } - - /** - * Get fully qualified path - * - * @return string - */ - public function basePath() - { - if ($this->dirname && $this->basename) { - return ($this->dirname .'/'. $this->basename); - } - - return null; - } - -} diff --git a/src/Intervention/Image/Filters/DemoFilter.php b/src/Intervention/Image/Filters/DemoFilter.php deleted file mode 100644 index 4e8f92b8..00000000 --- a/src/Intervention/Image/Filters/DemoFilter.php +++ /dev/null @@ -1,44 +0,0 @@ -size = is_numeric($size) ? intval($size) : self::DEFAULT_SIZE; - } - - /** - * Applies filter effects to given image - * - * @param \Intervention\Image\Image $image - * @return \Intervention\Image\Image - */ - public function applyFilter(Image $image) - { - $image->pixelate($this->size); - $image->greyscale(); - - return $image; - } -} diff --git a/src/Intervention/Image/Filters/FilterInterface.php b/src/Intervention/Image/Filters/FilterInterface.php deleted file mode 100644 index 88f6cbfe..00000000 --- a/src/Intervention/Image/Filters/FilterInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -a = ($value >> 24) & 0xFF; - $this->r = ($value >> 16) & 0xFF; - $this->g = ($value >> 8) & 0xFF; - $this->b = $value & 0xFF; - } - - /** - * Initiates color object from given array - * - * @param array $value - * @return \Intervention\Image\AbstractColor - */ - public function initFromArray($array) - { - $array = array_values($array); - - if (count($array) == 4) { - - // color array with alpha value - list($r, $g, $b, $a) = $array; - $this->a = $this->alpha2gd($a); - - } elseif (count($array) == 3) { - - // color array without alpha value - list($r, $g, $b) = $array; - $this->a = 0; - - } - - $this->r = $r; - $this->g = $g; - $this->b = $b; - } - - /** - * Initiates color object from given string - * - * @param string $value - * @return \Intervention\Image\AbstractColor - */ - public function initFromString($value) - { - if ($color = $this->rgbaFromString($value)) { - $this->r = $color[0]; - $this->g = $color[1]; - $this->b = $color[2]; - $this->a = $this->alpha2gd($color[3]); - } - } - - /** - * Initiates color object from given R, G and B values - * - * @param int $r - * @param int $g - * @param int $b - * @return \Intervention\Image\AbstractColor - */ - public function initFromRgb($r, $g, $b) - { - $this->r = intval($r); - $this->g = intval($g); - $this->b = intval($b); - $this->a = 0; - } - - /** - * Initiates color object from given R, G, B and A values - * - * @param int $r - * @param int $g - * @param int $b - * @param float $a - * @return \Intervention\Image\AbstractColor - */ - public function initFromRgba($r, $g, $b, $a = 1) - { - $this->r = intval($r); - $this->g = intval($g); - $this->b = intval($b); - $this->a = $this->alpha2gd($a); - } - - /** - * Initiates color object from given ImagickPixel object - * - * @param ImagickPixel $value - * @return \Intervention\Image\AbstractColor - */ - public function initFromObject($value) - { - throw new NotSupportedException( - "GD colors cannot init from ImagickPixel objects." - ); - } - - /** - * Calculates integer value of current color instance - * - * @return int - */ - public function getInt() - { - return ($this->a << 24) + ($this->r << 16) + ($this->g << 8) + $this->b; - } - - /** - * Calculates hexadecimal value of current color instance - * - * @param string $prefix - * @return string - */ - public function getHex($prefix = '') - { - return sprintf('%s%02x%02x%02x', $prefix, $this->r, $this->g, $this->b); - } - - /** - * Calculates RGB(A) in array format of current color instance - * - * @return array - */ - public function getArray() - { - return [$this->r, $this->g, $this->b, round(1 - $this->a / 127, 2)]; - } - - /** - * Calculates RGBA in string format of current color instance - * - * @return string - */ - public function getRgba() - { - return sprintf('rgba(%d, %d, %d, %.2F)', $this->r, $this->g, $this->b, round(1 - $this->a / 127, 2)); - } - - /** - * Determines if current color is different from given color - * - * @param AbstractColor $color - * @param int $tolerance - * @return boolean - */ - public function differs(AbstractColor $color, $tolerance = 0) - { - $color_tolerance = round($tolerance * 2.55); - $alpha_tolerance = round($tolerance * 1.27); - - $delta = [ - 'r' => abs($color->r - $this->r), - 'g' => abs($color->g - $this->g), - 'b' => abs($color->b - $this->b), - 'a' => abs($color->a - $this->a) - ]; - - return ( - $delta['r'] > $color_tolerance or - $delta['g'] > $color_tolerance or - $delta['b'] > $color_tolerance or - $delta['a'] > $alpha_tolerance - ); - } - - /** - * Convert rgba alpha (0-1) value to gd value (0-127) - * - * @param float $input - * @return int - */ - private function alpha2gd($input) - { - $oldMin = 0; - $oldMax = 1; - - $newMin = 127; - $newMax = 0; - - return ceil(((($input- $oldMin) * ($newMax - $newMin)) / ($oldMax - $oldMin)) + $newMin); - } -} diff --git a/src/Intervention/Image/Gd/Commands/BackupCommand.php b/src/Intervention/Image/Gd/Commands/BackupCommand.php deleted file mode 100644 index 310dc03a..00000000 --- a/src/Intervention/Image/Gd/Commands/BackupCommand.php +++ /dev/null @@ -1,25 +0,0 @@ -argument(0)->value(); - - // clone current image resource - $clone = clone $image; - $image->setBackup($clone->getCore(), $backupName); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/BlurCommand.php b/src/Intervention/Image/Gd/Commands/BlurCommand.php deleted file mode 100644 index c4fca0ea..00000000 --- a/src/Intervention/Image/Gd/Commands/BlurCommand.php +++ /dev/null @@ -1,25 +0,0 @@ -argument(0)->between(0, 100)->value(1); - - for ($i=0; $i < intval($amount); $i++) { - imagefilter($image->getCore(), IMG_FILTER_GAUSSIAN_BLUR); - } - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/BrightnessCommand.php b/src/Intervention/Image/Gd/Commands/BrightnessCommand.php deleted file mode 100644 index 4e48464b..00000000 --- a/src/Intervention/Image/Gd/Commands/BrightnessCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - - return imagefilter($image->getCore(), IMG_FILTER_BRIGHTNESS, ($level * 2.55)); - } -} diff --git a/src/Intervention/Image/Gd/Commands/ColorizeCommand.php b/src/Intervention/Image/Gd/Commands/ColorizeCommand.php deleted file mode 100644 index 410917b3..00000000 --- a/src/Intervention/Image/Gd/Commands/ColorizeCommand.php +++ /dev/null @@ -1,29 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - $green = $this->argument(1)->between(-100, 100)->required()->value(); - $blue = $this->argument(2)->between(-100, 100)->required()->value(); - - // normalize colorize levels - $red = round($red * 2.55); - $green = round($green * 2.55); - $blue = round($blue * 2.55); - - // apply filter - return imagefilter($image->getCore(), IMG_FILTER_COLORIZE, $red, $green, $blue); - } -} diff --git a/src/Intervention/Image/Gd/Commands/ContrastCommand.php b/src/Intervention/Image/Gd/Commands/ContrastCommand.php deleted file mode 100644 index 916c41f8..00000000 --- a/src/Intervention/Image/Gd/Commands/ContrastCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - - return imagefilter($image->getCore(), IMG_FILTER_CONTRAST, ($level * -1)); - } -} diff --git a/src/Intervention/Image/Gd/Commands/CropCommand.php b/src/Intervention/Image/Gd/Commands/CropCommand.php deleted file mode 100644 index b7f59542..00000000 --- a/src/Intervention/Image/Gd/Commands/CropCommand.php +++ /dev/null @@ -1,40 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->required()->value(); - $x = $this->argument(2)->type('digit')->value(); - $y = $this->argument(3)->type('digit')->value(); - - if (is_null($width) || is_null($height)) { - throw new \Intervention\Image\Exception\InvalidArgumentException( - "Width and height of cutout needs to be defined." - ); - } - - $cropped = new Size($width, $height); - $position = new Point($x, $y); - - // align boxes - if (is_null($x) && is_null($y)) { - $position = $image->getSize()->align('center')->relativePosition($cropped->align('center')); - } - - // crop image core - return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height); - } -} diff --git a/src/Intervention/Image/Gd/Commands/DestroyCommand.php b/src/Intervention/Image/Gd/Commands/DestroyCommand.php deleted file mode 100644 index 4503d10f..00000000 --- a/src/Intervention/Image/Gd/Commands/DestroyCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -getCore()); - - // destroy backups - foreach ($image->getBackups() as $backup) { - imagedestroy($backup); - } - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/FillCommand.php b/src/Intervention/Image/Gd/Commands/FillCommand.php deleted file mode 100644 index cf190821..00000000 --- a/src/Intervention/Image/Gd/Commands/FillCommand.php +++ /dev/null @@ -1,69 +0,0 @@ -argument(0)->value(); - $x = $this->argument(1)->type('digit')->value(); - $y = $this->argument(2)->type('digit')->value(); - - $width = $image->getWidth(); - $height = $image->getHeight(); - $resource = $image->getCore(); - - try { - - // set image tile filling - $source = new Decoder; - $tile = $source->init($filling); - imagesettile($image->getCore(), $tile->getCore()); - $filling = IMG_COLOR_TILED; - - } catch (\Intervention\Image\Exception\NotReadableException $e) { - - // set solid color filling - $color = new Color($filling); - $filling = $color->getInt(); - } - - imagealphablending($resource, true); - - if (is_int($x) && is_int($y)) { - - // resource should be visible through transparency - $base = $image->getDriver()->newImage($width, $height)->getCore(); - imagecopy($base, $resource, 0, 0, 0, 0, $width, $height); - - // floodfill if exact position is defined - imagefill($resource, $x, $y, $filling); - - // copy filled original over base - imagecopy($base, $resource, 0, 0, 0, 0, $width, $height); - - // set base as new resource-core - $image->setCore($base); - imagedestroy($resource); - - } else { - // fill whole image otherwise - imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling); - } - - isset($tile) ? imagedestroy($tile->getCore()) : null; - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/FitCommand.php b/src/Intervention/Image/Gd/Commands/FitCommand.php deleted file mode 100644 index d861ad94..00000000 --- a/src/Intervention/Image/Gd/Commands/FitCommand.php +++ /dev/null @@ -1,32 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->value($width); - $constraints = $this->argument(2)->type('closure')->value(); - $position = $this->argument(3)->type('string')->value('center'); - - // calculate size - $cropped = $image->getSize()->fit(new Size($width, $height), $position); - $resized = clone $cropped; - $resized = $resized->resize($width, $height, $constraints); - - // modify image - $this->modify($image, 0, 0, $cropped->pivot->x, $cropped->pivot->y, $resized->getWidth(), $resized->getHeight(), $cropped->getWidth(), $cropped->getHeight()); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/FlipCommand.php b/src/Intervention/Image/Gd/Commands/FlipCommand.php deleted file mode 100644 index aa8f230e..00000000 --- a/src/Intervention/Image/Gd/Commands/FlipCommand.php +++ /dev/null @@ -1,37 +0,0 @@ -argument(0)->value('h'); - - $size = $image->getSize(); - $dst = clone $size; - - switch (strtolower($mode)) { - case 2: - case 'v': - case 'vert': - case 'vertical': - $size->pivot->y = $size->height - 1; - $size->height = $size->height * (-1); - break; - - default: - $size->pivot->x = $size->width - 1; - $size->width = $size->width * (-1); - break; - } - - return $this->modify($image, 0, 0, $size->pivot->x, $size->pivot->y, $dst->width, $dst->height, $size->width, $size->height); - } -} diff --git a/src/Intervention/Image/Gd/Commands/GammaCommand.php b/src/Intervention/Image/Gd/Commands/GammaCommand.php deleted file mode 100644 index 7de0fb8a..00000000 --- a/src/Intervention/Image/Gd/Commands/GammaCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - - return imagegammacorrect($image->getCore(), 1, $gamma); - } -} diff --git a/src/Intervention/Image/Gd/Commands/GetSizeCommand.php b/src/Intervention/Image/Gd/Commands/GetSizeCommand.php deleted file mode 100644 index 9eb7e209..00000000 --- a/src/Intervention/Image/Gd/Commands/GetSizeCommand.php +++ /dev/null @@ -1,25 +0,0 @@ -setOutput(new Size( - imagesx($image->getCore()), - imagesy($image->getCore()) - )); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/GreyscaleCommand.php b/src/Intervention/Image/Gd/Commands/GreyscaleCommand.php deleted file mode 100644 index 12921e79..00000000 --- a/src/Intervention/Image/Gd/Commands/GreyscaleCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -getCore(), IMG_FILTER_GRAYSCALE); - } -} diff --git a/src/Intervention/Image/Gd/Commands/HeightenCommand.php b/src/Intervention/Image/Gd/Commands/HeightenCommand.php deleted file mode 100644 index d31e9cde..00000000 --- a/src/Intervention/Image/Gd/Commands/HeightenCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $additionalConstraints = $this->argument(1)->type('closure')->value(); - - $this->arguments[0] = null; - $this->arguments[1] = $height; - $this->arguments[2] = function ($constraint) use ($additionalConstraints) { - $constraint->aspectRatio(); - if(is_callable($additionalConstraints)) - $additionalConstraints($constraint); - }; - - return parent::execute($image); - } -} diff --git a/src/Intervention/Image/Gd/Commands/InsertCommand.php b/src/Intervention/Image/Gd/Commands/InsertCommand.php deleted file mode 100644 index 47c77039..00000000 --- a/src/Intervention/Image/Gd/Commands/InsertCommand.php +++ /dev/null @@ -1,34 +0,0 @@ -argument(0)->required()->value(); - $position = $this->argument(1)->type('string')->value(); - $x = $this->argument(2)->type('digit')->value(0); - $y = $this->argument(3)->type('digit')->value(0); - - // build watermark - $watermark = $image->getDriver()->init($source); - - // define insertion point - $image_size = $image->getSize()->align($position, $x, $y); - $watermark_size = $watermark->getSize()->align($position); - $target = $image_size->relativePosition($watermark_size); - - // insert image at position - imagealphablending($image->getCore(), true); - return imagecopy($image->getCore(), $watermark->getCore(), $target->x, $target->y, 0, 0, $watermark_size->width, $watermark_size->height); - } -} diff --git a/src/Intervention/Image/Gd/Commands/InterlaceCommand.php b/src/Intervention/Image/Gd/Commands/InterlaceCommand.php deleted file mode 100644 index e3461cb0..00000000 --- a/src/Intervention/Image/Gd/Commands/InterlaceCommand.php +++ /dev/null @@ -1,23 +0,0 @@ -argument(0)->type('bool')->value(true); - - imageinterlace($image->getCore(), $mode); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/InvertCommand.php b/src/Intervention/Image/Gd/Commands/InvertCommand.php deleted file mode 100644 index 1a514f1d..00000000 --- a/src/Intervention/Image/Gd/Commands/InvertCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -getCore(), IMG_FILTER_NEGATE); - } -} diff --git a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php b/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php deleted file mode 100644 index 0baed7e9..00000000 --- a/src/Intervention/Image/Gd/Commands/LimitColorsCommand.php +++ /dev/null @@ -1,53 +0,0 @@ -argument(0)->value(); - $matte = $this->argument(1)->value(); - - // get current image size - $size = $image->getSize(); - - // create empty canvas - $resource = imagecreatetruecolor($size->width, $size->height); - - // define matte - if (is_null($matte)) { - $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127); - } else { - $matte = $image->getDriver()->parseColor($matte)->getInt(); - } - - // fill with matte and copy original image - imagefill($resource, 0, 0, $matte); - - // set transparency - imagecolortransparent($resource, $matte); - - // copy original image - imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height); - - if (is_numeric($count) && $count <= 256) { - // decrease colors - imagetruecolortopalette($resource, true, $count); - } - - // set new resource - $image->setCore($resource); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/MaskCommand.php b/src/Intervention/Image/Gd/Commands/MaskCommand.php deleted file mode 100644 index 4c61429b..00000000 --- a/src/Intervention/Image/Gd/Commands/MaskCommand.php +++ /dev/null @@ -1,83 +0,0 @@ -argument(0)->value(); - $mask_w_alpha = $this->argument(1)->type('bool')->value(false); - - $image_size = $image->getSize(); - - // create empty canvas - $canvas = $image->getDriver()->newImage($image_size->width, $image_size->height, [0,0,0,0]); - - // build mask image from source - $mask = $image->getDriver()->init($mask_source); - $mask_size = $mask->getSize(); - - // resize mask to size of current image (if necessary) - if ($mask_size != $image_size) { - $mask->resize($image_size->width, $image_size->height); - } - - imagealphablending($canvas->getCore(), false); - - if ( ! $mask_w_alpha) { - // mask from greyscale image - imagefilter($mask->getCore(), IMG_FILTER_GRAYSCALE); - } - - // redraw old image pixel by pixel considering alpha map - for ($x=0; $x < $image_size->width; $x++) { - for ($y=0; $y < $image_size->height; $y++) { - - $color = $image->pickColor($x, $y, 'array'); - $alpha = $mask->pickColor($x, $y, 'array'); - - if ($mask_w_alpha) { - $alpha = $alpha[3]; // use alpha channel as mask - } else { - - if ($alpha[3] == 0) { // transparent as black - $alpha = 0; - } else { - - // $alpha = floatval(round((($alpha[0] + $alpha[1] + $alpha[3]) / 3) / 255, 2)); - - // image is greyscale, so channel doesn't matter (use red channel) - $alpha = floatval(round($alpha[0] / 255, 2)); - } - - } - - // preserve alpha of original image... - if ($color[3] < $alpha) { - $alpha = $color[3]; - } - - // replace alpha value - $color[3] = $alpha; - - // redraw pixel - $canvas->pixel($color, $x, $y); - } - } - - - // replace current image with masked instance - $image->setCore($canvas->getCore()); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/OpacityCommand.php b/src/Intervention/Image/Gd/Commands/OpacityCommand.php deleted file mode 100644 index 48492d24..00000000 --- a/src/Intervention/Image/Gd/Commands/OpacityCommand.php +++ /dev/null @@ -1,31 +0,0 @@ -argument(0)->between(0, 100)->required()->value(); - - // get size of image - $size = $image->getSize(); - - // build temp alpha mask - $mask_color = sprintf('rgba(0, 0, 0, %.1F)', $transparency / 100); - $mask = $image->getDriver()->newImage($size->width, $size->height, $mask_color); - - // mask image - $image->mask($mask->getCore(), true); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/PickColorCommand.php b/src/Intervention/Image/Gd/Commands/PickColorCommand.php deleted file mode 100644 index bad96f49..00000000 --- a/src/Intervention/Image/Gd/Commands/PickColorCommand.php +++ /dev/null @@ -1,37 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $y = $this->argument(1)->type('digit')->required()->value(); - $format = $this->argument(2)->type('string')->value('array'); - - // pick color - $color = imagecolorat($image->getCore(), $x, $y); - - if ( ! imageistruecolor($image->getCore())) { - $color = imagecolorsforindex($image->getCore(), $color); - $color['alpha'] = round(1 - $color['alpha'] / 127, 2); - } - - $color = new Color($color); - - // format to output - $this->setOutput($color->format($format)); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/PixelCommand.php b/src/Intervention/Image/Gd/Commands/PixelCommand.php deleted file mode 100644 index 2a90ce34..00000000 --- a/src/Intervention/Image/Gd/Commands/PixelCommand.php +++ /dev/null @@ -1,25 +0,0 @@ -argument(0)->required()->value(); - $color = new Color($color); - $x = $this->argument(1)->type('digit')->required()->value(); - $y = $this->argument(2)->type('digit')->required()->value(); - - return imagesetpixel($image->getCore(), $x, $y, $color->getInt()); - } -} diff --git a/src/Intervention/Image/Gd/Commands/PixelateCommand.php b/src/Intervention/Image/Gd/Commands/PixelateCommand.php deleted file mode 100644 index 0934797a..00000000 --- a/src/Intervention/Image/Gd/Commands/PixelateCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->type('digit')->value(10); - - return imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $size, true); - } -} diff --git a/src/Intervention/Image/Gd/Commands/ResetCommand.php b/src/Intervention/Image/Gd/Commands/ResetCommand.php deleted file mode 100644 index a68b75ea..00000000 --- a/src/Intervention/Image/Gd/Commands/ResetCommand.php +++ /dev/null @@ -1,39 +0,0 @@ -argument(0)->value(); - $backup = $image->getBackup($backupName); - - if (is_resource($backup) || $backup instanceof \GdImage) { - - // destroy current resource - imagedestroy($image->getCore()); - - // clone backup - $backup = $image->getDriver()->cloneCore($backup); - - // reset to new resource - $image->setCore($backup); - - return true; - } - - throw new RuntimeException( - "Backup not available. Call backup() before reset()." - ); - } -} diff --git a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php b/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php deleted file mode 100644 index 73f3df30..00000000 --- a/src/Intervention/Image/Gd/Commands/ResizeCanvasCommand.php +++ /dev/null @@ -1,83 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->required()->value(); - $anchor = $this->argument(2)->value('center'); - $relative = $this->argument(3)->type('boolean')->value(false); - $bgcolor = $this->argument(4)->value(); - - $original_width = $image->getWidth(); - $original_height = $image->getHeight(); - - // check of only width or height is set - $width = is_null($width) ? $original_width : intval($width); - $height = is_null($height) ? $original_height : intval($height); - - // check on relative width/height - if ($relative) { - $width = $original_width + $width; - $height = $original_height + $height; - } - - // check for negative width/height - $width = ($width <= 0) ? $width + $original_width : $width; - $height = ($height <= 0) ? $height + $original_height : $height; - - // create new canvas - $canvas = $image->getDriver()->newImage($width, $height, $bgcolor); - - // set copy position - $canvas_size = $canvas->getSize()->align($anchor); - $image_size = $image->getSize()->align($anchor); - $canvas_pos = $image_size->relativePosition($canvas_size); - $image_pos = $canvas_size->relativePosition($image_size); - - if ($width <= $original_width) { - $dst_x = 0; - $src_x = $canvas_pos->x; - $src_w = $canvas_size->width; - } else { - $dst_x = $image_pos->x; - $src_x = 0; - $src_w = $original_width; - } - - if ($height <= $original_height) { - $dst_y = 0; - $src_y = $canvas_pos->y; - $src_h = $canvas_size->height; - } else { - $dst_y = $image_pos->y; - $src_y = 0; - $src_h = $original_height; - } - - // make image area transparent to keep transparency - // even if background-color is set - $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127); - imagealphablending($canvas->getCore(), false); // do not blend / just overwrite - imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent); - - // copy image into new canvas - imagecopy($canvas->getCore(), $image->getCore(), $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h); - - // set new core to canvas - $image->setCore($canvas->getCore()); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/ResizeCommand.php b/src/Intervention/Image/Gd/Commands/ResizeCommand.php deleted file mode 100644 index 382d9709..00000000 --- a/src/Intervention/Image/Gd/Commands/ResizeCommand.php +++ /dev/null @@ -1,84 +0,0 @@ -argument(0)->value(); - $height = $this->argument(1)->value(); - $constraints = $this->argument(2)->type('closure')->value(); - - // resize box - $resized = $image->getSize()->resize($width, $height, $constraints); - - // modify image - $this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight()); - - return true; - } - - /** - * Wrapper function for 'imagecopyresampled' - * - * @param Image $image - * @param int $dst_x - * @param int $dst_y - * @param int $src_x - * @param int $src_y - * @param int $dst_w - * @param int $dst_h - * @param int $src_w - * @param int $src_h - * @return boolean - */ - protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) - { - // create new image - $modified = imagecreatetruecolor($dst_w, $dst_h); - - // get current image - $resource = $image->getCore(); - - // preserve transparency - $transIndex = imagecolortransparent($resource); - - if ($transIndex != -1) { - $rgba = imagecolorsforindex($modified, $transIndex); - $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127); - imagefill($modified, 0, 0, $transColor); - imagecolortransparent($modified, $transColor); - } else { - imagealphablending($modified, false); - imagesavealpha($modified, true); - } - - // copy content from resource - $result = imagecopyresampled( - $modified, - $resource, - $dst_x, - $dst_y, - $src_x, - $src_y, - $dst_w, - $dst_h, - $src_w, - $src_h - ); - - // set new content as recource - $image->setCore($modified); - - return $result; - } -} diff --git a/src/Intervention/Image/Gd/Commands/RotateCommand.php b/src/Intervention/Image/Gd/Commands/RotateCommand.php deleted file mode 100644 index 682ec0d4..00000000 --- a/src/Intervention/Image/Gd/Commands/RotateCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $color = $this->argument(1)->value(); - $color = new Color($color); - - // restrict rotations beyond 360 degrees, since the end result is the same - $angle = fmod($angle, 360); - - // rotate image - $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt())); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Commands/SharpenCommand.php b/src/Intervention/Image/Gd/Commands/SharpenCommand.php deleted file mode 100644 index 782e5650..00000000 --- a/src/Intervention/Image/Gd/Commands/SharpenCommand.php +++ /dev/null @@ -1,34 +0,0 @@ -argument(0)->between(0, 100)->value(10); - - // build matrix - $min = $amount >= 10 ? $amount * -0.01 : 0; - $max = $amount * -0.025; - $abs = ((4 * $min + 4 * $max) * -1) + 1; - $div = 1; - - $matrix = [ - [$min, $max, $min], - [$max, $abs, $max], - [$min, $max, $min] - ]; - - // apply the matrix - return imageconvolution($image->getCore(), $matrix, $div, 0); - } -} diff --git a/src/Intervention/Image/Gd/Commands/TrimCommand.php b/src/Intervention/Image/Gd/Commands/TrimCommand.php deleted file mode 100644 index 2e369752..00000000 --- a/src/Intervention/Image/Gd/Commands/TrimCommand.php +++ /dev/null @@ -1,176 +0,0 @@ -argument(0)->type('string')->value(); - $away = $this->argument(1)->value(); - $tolerance = $this->argument(2)->type('numeric')->value(0); - $feather = $this->argument(3)->type('numeric')->value(0); - - $width = $image->getWidth(); - $height = $image->getHeight(); - - // default values - $checkTransparency = false; - - // define borders to trim away - if (is_null($away)) { - $away = ['top', 'right', 'bottom', 'left']; - } elseif (is_string($away)) { - $away = [$away]; - } - - // lower border names - foreach ($away as $key => $value) { - $away[$key] = strtolower($value); - } - - // define base color position - switch (strtolower($base)) { - case 'transparent': - case 'trans': - $checkTransparency = true; - $base_x = 0; - $base_y = 0; - break; - - case 'bottom-right': - case 'right-bottom': - $base_x = $width - 1; - $base_y = $height - 1; - break; - - default: - case 'top-left': - case 'left-top': - $base_x = 0; - $base_y = 0; - break; - } - - // pick base color - if ($checkTransparency) { - $color = new Color; // color will only be used to compare alpha channel - } else { - $color = $image->pickColor($base_x, $base_y, 'object'); - } - - $top_x = 0; - $top_y = 0; - $bottom_x = $width; - $bottom_y = $height; - - // search upper part of image for colors to trim away - if (in_array('top', $away)) { - - for ($y=0; $y < ceil($height/2); $y++) { - for ($x=0; $x < $width; $x++) { - - $checkColor = $image->pickColor($x, $y, 'object'); - - if ($checkTransparency) { - $checkColor->r = $color->r; - $checkColor->g = $color->g; - $checkColor->b = $color->b; - } - - if ($color->differs($checkColor, $tolerance)) { - $top_y = max(0, $y - $feather); - break 2; - } - - } - } - - } - - // search left part of image for colors to trim away - if (in_array('left', $away)) { - - for ($x=0; $x < ceil($width/2); $x++) { - for ($y=$top_y; $y < $height; $y++) { - - $checkColor = $image->pickColor($x, $y, 'object'); - - if ($checkTransparency) { - $checkColor->r = $color->r; - $checkColor->g = $color->g; - $checkColor->b = $color->b; - } - - if ($color->differs($checkColor, $tolerance)) { - $top_x = max(0, $x - $feather); - break 2; - } - - } - } - - } - - // search lower part of image for colors to trim away - if (in_array('bottom', $away)) { - - for ($y=($height-1); $y >= floor($height/2)-1; $y--) { - for ($x=$top_x; $x < $width; $x++) { - - $checkColor = $image->pickColor($x, $y, 'object'); - - if ($checkTransparency) { - $checkColor->r = $color->r; - $checkColor->g = $color->g; - $checkColor->b = $color->b; - } - - if ($color->differs($checkColor, $tolerance)) { - $bottom_y = min($height, $y+1 + $feather); - break 2; - } - - } - } - - } - - // search right part of image for colors to trim away - if (in_array('right', $away)) { - - for ($x=($width-1); $x >= floor($width/2)-1; $x--) { - for ($y=$top_y; $y < $bottom_y; $y++) { - - $checkColor = $image->pickColor($x, $y, 'object'); - - if ($checkTransparency) { - $checkColor->r = $color->r; - $checkColor->g = $color->g; - $checkColor->b = $color->b; - } - - if ($color->differs($checkColor, $tolerance)) { - $bottom_x = min($width, $x+1 + $feather); - break 2; - } - - } - } - - } - - - // trim parts of image - return $this->modify($image, 0, 0, $top_x, $top_y, ($bottom_x-$top_x), ($bottom_y-$top_y), ($bottom_x-$top_x), ($bottom_y-$top_y)); - - } -} diff --git a/src/Intervention/Image/Gd/Commands/WidenCommand.php b/src/Intervention/Image/Gd/Commands/WidenCommand.php deleted file mode 100644 index 43000d5d..00000000 --- a/src/Intervention/Image/Gd/Commands/WidenCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $additionalConstraints = $this->argument(1)->type('closure')->value(); - - $this->arguments[0] = $width; - $this->arguments[1] = null; - $this->arguments[2] = function ($constraint) use ($additionalConstraints) { - $constraint->aspectRatio(); - if(is_callable($additionalConstraints)) - $additionalConstraints($constraint); - }; - - return parent::execute($image); - } -} diff --git a/src/Intervention/Image/Gd/Decoder.php b/src/Intervention/Image/Gd/Decoder.php deleted file mode 100644 index f5c34aa5..00000000 --- a/src/Intervention/Image/Gd/Decoder.php +++ /dev/null @@ -1,171 +0,0 @@ -gdResourceToTruecolor($core); - - // build image - $image = $this->initFromGdResource($core); - $image->mime = $mime; - $image->setFileInfoFromPath($path); - - return $image; - } - - /** - * Initiates new image from GD resource - * - * @param Resource $resource - * @return \Intervention\Image\Image - */ - public function initFromGdResource($resource) - { - return new Image(new Driver, $resource); - } - - /** - * Initiates new image from Imagick object - * - * @param Imagick $object - * @return \Intervention\Image\Image - */ - public function initFromImagick(\Imagick $object) - { - throw new NotSupportedException( - "Gd driver is unable to init from Imagick object." - ); - } - - /** - * Initiates new image from binary data - * - * @param string $data - * @return \Intervention\Image\Image - */ - public function initFromBinary($binary) - { - $resource = @imagecreatefromstring($binary); - - if ($resource === false) { - throw new NotReadableException( - "Unable to init from given binary data." - ); - } - - $image = $this->initFromGdResource($resource); - $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary); - - return $image; - } - - /** - * Transform GD resource into Truecolor version - * - * @param resource $resource - * @return bool - */ - public function gdResourceToTruecolor(&$resource) - { - $width = imagesx($resource); - $height = imagesy($resource); - - // new canvas - $canvas = imagecreatetruecolor($width, $height); - - // fill with transparent color - imagealphablending($canvas, false); - $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127); - imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent); - imagecolortransparent($canvas, $transparent); - imagealphablending($canvas, true); - - // copy original - imagecopy($canvas, $resource, 0, 0, 0, 0, $width, $height); - imagedestroy($resource); - - $resource = $canvas; - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Driver.php b/src/Intervention/Image/Gd/Driver.php deleted file mode 100644 index 5f2f23ea..00000000 --- a/src/Intervention/Image/Gd/Driver.php +++ /dev/null @@ -1,89 +0,0 @@ -coreAvailable()) { - throw new NotSupportedException( - "GD Library extension not available with this PHP installation." - ); - } - - $this->decoder = $decoder ? $decoder : new Decoder; - $this->encoder = $encoder ? $encoder : new Encoder; - } - - /** - * Creates new image instance - * - * @param int $width - * @param int $height - * @param mixed $background - * @return \Intervention\Image\Image - */ - public function newImage($width, $height, $background = null) - { - // create empty resource - $core = imagecreatetruecolor($width, $height); - $image = new Image(new static, $core); - - // set background color - $background = new Color($background); - imagefill($image->getCore(), 0, 0, $background->getInt()); - - return $image; - } - - /** - * Reads given string into color object - * - * @param string $value - * @return AbstractColor - */ - public function parseColor($value) - { - return new Color($value); - } - - /** - * Checks if core module installation is available - * - * @return boolean - */ - protected function coreAvailable() - { - return (extension_loaded('gd') && function_exists('gd_info')); - } - - /** - * Returns clone of given core - * - * @return mixed - */ - public function cloneCore($core) - { - $width = imagesx($core); - $height = imagesy($core); - $clone = imagecreatetruecolor($width, $height); - imagealphablending($clone, false); - imagesavealpha($clone, true); - $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127); - imagefill($clone, 0, 0, $transparency); - - imagecopy($clone, $core, 0, 0, 0, 0, $width, $height); - - return $clone; - } -} diff --git a/src/Intervention/Image/Gd/Encoder.php b/src/Intervention/Image/Gd/Encoder.php deleted file mode 100644 index 559d60dc..00000000 --- a/src/Intervention/Image/Gd/Encoder.php +++ /dev/null @@ -1,180 +0,0 @@ -image->getCore(), null, $this->quality); - $this->image->mime = image_type_to_mime_type(IMAGETYPE_JPEG); - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as PNG string - * - * @return string - */ - protected function processPng() - { - ob_start(); - $resource = $this->image->getCore(); - imagealphablending($resource, false); - imagesavealpha($resource, true); - imagepng($resource, null, -1); - $this->image->mime = image_type_to_mime_type(IMAGETYPE_PNG); - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as GIF string - * - * @return string - */ - protected function processGif() - { - ob_start(); - imagegif($this->image->getCore()); - $this->image->mime = image_type_to_mime_type(IMAGETYPE_GIF); - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as WEBP string - * - * @return string - */ - protected function processWebp() - { - if ( ! function_exists('imagewebp')) { - throw new NotSupportedException( - "Webp format is not supported by PHP installation." - ); - } - - ob_start(); - imagepalettetotruecolor($this->image->getCore()); - imagealphablending($this->image->getCore(), true); - imagesavealpha($this->image->getCore(), true); - imagewebp($this->image->getCore(), null, $this->quality); - $this->image->mime = defined('IMAGETYPE_WEBP') ? image_type_to_mime_type(IMAGETYPE_WEBP) : 'image/webp'; - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as TIFF string - * - * @return string - */ - protected function processTiff() - { - throw new NotSupportedException( - "TIFF format is not supported by Gd Driver." - ); - } - - /** - * Processes and returns encoded image as BMP string - * - * @return string - */ - protected function processBmp() - { - if ( ! function_exists('imagebmp')) { - throw new NotSupportedException( - "BMP format is not supported by PHP installation." - ); - } - - ob_start(); - imagebmp($this->image->getCore()); - $this->image->mime = defined('IMAGETYPE_BMP') ? image_type_to_mime_type(IMAGETYPE_BMP) : 'image/bmp'; - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as ICO string - * - * @return string - */ - protected function processIco() - { - throw new NotSupportedException( - "ICO format is not supported by Gd Driver." - ); - } - - /** - * Processes and returns encoded image as PSD string - * - * @return string - */ - protected function processPsd() - { - throw new NotSupportedException( - "PSD format is not supported by Gd Driver." - ); - } - - /** - * Processes and returns encoded image as AVIF string - * - * @return string - */ - protected function processAvif() - { - if ( ! function_exists('imageavif')) { - throw new NotSupportedException( - "AVIF format is not supported by PHP installation." - ); - } - - ob_start(); - $resource = $this->image->getCore(); - imagepalettetotruecolor($resource); - imagealphablending($resource, true); - imagesavealpha($resource, true); - imageavif($resource, null, $this->quality); - $this->image->mime = defined('IMAGETYPE_AVIF') ? image_type_to_mime_type(IMAGETYPE_AVIF) : 'image/avif'; - $buffer = ob_get_contents(); - ob_end_clean(); - - return $buffer; - } - - /** - * Processes and returns encoded image as HEIC string - * - * @return string - */ - protected function processHeic() - { - throw new NotSupportedException( - "HEIC format is not supported by Gd Driver." - ); - } -} diff --git a/src/Intervention/Image/Gd/Font.php b/src/Intervention/Image/Gd/Font.php deleted file mode 100644 index 3f588878..00000000 --- a/src/Intervention/Image/Gd/Font.php +++ /dev/null @@ -1,277 +0,0 @@ -size * 0.75)); - } - - /** - * Filter function to access internal integer font values - * - * @return int - */ - private function getInternalFont() - { - $internalfont = is_null($this->file) ? 1 : $this->file; - $internalfont = is_numeric($internalfont) ? $internalfont : false; - - if ( ! in_array($internalfont, [1, 2, 3, 4, 5])) { - throw new NotSupportedException( - sprintf('Internal GD font (%s) not available. Use only 1-5.', $internalfont) - ); - } - - return intval($internalfont); - } - - /** - * Get width of an internal font character - * - * @return int - */ - private function getInternalFontWidth() - { - return $this->getInternalFont() + 4; - } - - /** - * Get height of an internal font character - * - * @return int - */ - private function getInternalFontHeight() - { - switch ($this->getInternalFont()) { - case 1: - return 8; - - case 2: - return 14; - - case 3: - return 14; - - case 4: - return 16; - - case 5: - return 16; - } - } - - /** - * Calculates bounding box of current font setting - * - * @return Array - */ - public function getBoxSize() - { - $box = []; - - if ($this->hasApplicableFontFile()) { - - // imagettfbbox() converts numeric entities to their respective - // character. Preserve any originally double encoded entities to be - // represented as is. - // eg: &#160; will render   rather than its character. - $this->text = preg_replace('/&(#(?:x[a-fA-F0-9]+|[0-9]+);)/', '&\1', $this->text); - $this->text = mb_encode_numericentity($this->text, array(0x0080, 0xffff, 0, 0xffff), 'UTF-8'); - - // get bounding box with angle 0 - $box = imagettfbbox($this->getPointSize(), 0, $this->file, $this->text); - - // rotate points manually - if ($this->angle != 0) { - - $angle = pi() * 2 - $this->angle * pi() * 2 / 360; - - for ($i=0; $i<4; $i++) { - $x = $box[$i * 2]; - $y = $box[$i * 2 + 1]; - $box[$i * 2] = cos($angle) * $x - sin($angle) * $y; - $box[$i * 2 + 1] = sin($angle) * $x + cos($angle) * $y; - } - } - - $box['width'] = intval(abs($box[4] - $box[0])); - $box['height'] = intval(abs($box[5] - $box[1])); - - } else { - - // get current internal font size - $width = $this->getInternalFontWidth(); - $height = $this->getInternalFontHeight(); - - if (strlen($this->text) == 0) { - // no text -> no boxsize - $box['width'] = 0; - $box['height'] = 0; - } else { - // calculate boxsize - $box['width'] = strlen($this->text) * $width; - $box['height'] = $height; - } - } - - return $box; - } - - /** - * Draws font to given image at given position - * - * @param Image $image - * @param int $posx - * @param int $posy - * @return void - */ - public function applyToImage(Image $image, $posx = 0, $posy = 0) - { - // parse text color - $color = new Color($this->color); - - if ($this->hasApplicableFontFile()) { - - if ($this->angle != 0 || is_string($this->align) || is_string($this->valign)) { - - $box = $this->getBoxSize(); - - $align = is_null($this->align) ? 'left' : strtolower($this->align); - $valign = is_null($this->valign) ? 'bottom' : strtolower($this->valign); - - // correction on position depending on v/h alignment - switch ($align.'-'.$valign) { - - case 'center-top': - $posx = $posx - round(($box[6]+$box[4])/2); - $posy = $posy - round(($box[7]+$box[5])/2); - break; - - case 'right-top': - $posx = $posx - $box[4]; - $posy = $posy - $box[5]; - break; - - case 'left-top': - $posx = $posx - $box[6]; - $posy = $posy - $box[7]; - break; - - case 'center-center': - case 'center-middle': - $posx = $posx - round(($box[0]+$box[4])/2); - $posy = $posy - round(($box[1]+$box[5])/2); - break; - - case 'right-center': - case 'right-middle': - $posx = $posx - round(($box[2]+$box[4])/2); - $posy = $posy - round(($box[3]+$box[5])/2); - break; - - case 'left-center': - case 'left-middle': - $posx = $posx - round(($box[0]+$box[6])/2); - $posy = $posy - round(($box[1]+$box[7])/2); - break; - - case 'center-bottom': - $posx = $posx - round(($box[0]+$box[2])/2); - $posy = $posy - round(($box[1]+$box[3])/2); - break; - - case 'right-bottom': - $posx = $posx - $box[2]; - $posy = $posy - $box[3]; - break; - - case 'left-bottom': - $posx = $posx - $box[0]; - $posy = $posy - $box[1]; - break; - } - } - - // enable alphablending for imagettftext - imagealphablending($image->getCore(), true); - - // draw ttf text - imagettftext($image->getCore(), $this->getPointSize(), $this->angle, $posx, $posy, $color->getInt(), $this->file, $this->text); - - } else { - - // get box size - $box = $this->getBoxSize(); - $width = $box['width']; - $height = $box['height']; - - // internal font specific position corrections - if ($this->getInternalFont() == 1) { - $top_correction = 1; - $bottom_correction = 2; - } elseif ($this->getInternalFont() == 3) { - $top_correction = 2; - $bottom_correction = 4; - } else { - $top_correction = 3; - $bottom_correction = 4; - } - - // x-position corrections for horizontal alignment - switch (strtolower($this->align)) { - case 'center': - $posx = ceil($posx - ($width / 2)); - break; - - case 'right': - $posx = ceil($posx - $width) + 1; - break; - } - - // y-position corrections for vertical alignment - switch (strtolower($this->valign)) { - case 'center': - case 'middle': - $posy = ceil($posy - ($height / 2)); - break; - - case 'top': - $posy = ceil($posy - $top_correction); - break; - - default: - case 'bottom': - $posy = round($posy - $height + $bottom_correction); - break; - } - - // draw text - imagestring($image->getCore(), $this->getInternalFont(), $posx, $posy, $this->text, $color->getInt()); - } - } - - /** - * Set text kerning - * - * @param string $kerning - * @return void - */ - public function kerning($kerning) - { - throw new \Intervention\Image\Exception\NotSupportedException( - "Kerning is not supported by GD driver." - ); - } - -} diff --git a/src/Intervention/Image/Gd/Shapes/CircleShape.php b/src/Intervention/Image/Gd/Shapes/CircleShape.php deleted file mode 100644 index c3c42144..00000000 --- a/src/Intervention/Image/Gd/Shapes/CircleShape.php +++ /dev/null @@ -1,40 +0,0 @@ -width = is_numeric($diameter) ? intval($diameter) : $this->diameter; - $this->height = is_numeric($diameter) ? intval($diameter) : $this->diameter; - $this->diameter = is_numeric($diameter) ? intval($diameter) : $this->diameter; - } - - /** - * Draw current circle on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - return parent::applyToImage($image, $x, $y); - } -} diff --git a/src/Intervention/Image/Gd/Shapes/EllipseShape.php b/src/Intervention/Image/Gd/Shapes/EllipseShape.php deleted file mode 100644 index 78e5e4a5..00000000 --- a/src/Intervention/Image/Gd/Shapes/EllipseShape.php +++ /dev/null @@ -1,65 +0,0 @@ -width = is_numeric($width) ? intval($width) : $this->width; - $this->height = is_numeric($height) ? intval($height) : $this->height; - } - - /** - * Draw ellipse instance on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - // parse background color - $background = new Color($this->background); - - if ($this->hasBorder()) { - // slightly smaller ellipse to keep 1px bordered edges clean - imagefilledellipse($image->getCore(), $x, $y, $this->width-1, $this->height-1, $background->getInt()); - - $border_color = new Color($this->border_color); - imagesetthickness($image->getCore(), $this->border_width); - - // gd's imageellipse doesn't respect imagesetthickness so i use imagearc with 359.9 degrees here - imagearc($image->getCore(), $x, $y, $this->width, $this->height, 0, 359.99, $border_color->getInt()); - } else { - imagefilledellipse($image->getCore(), $x, $y, $this->width, $this->height, $background->getInt()); - } - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Shapes/LineShape.php b/src/Intervention/Image/Gd/Shapes/LineShape.php deleted file mode 100644 index ea38b513..00000000 --- a/src/Intervention/Image/Gd/Shapes/LineShape.php +++ /dev/null @@ -1,90 +0,0 @@ -x = is_numeric($x) ? intval($x) : $this->x; - $this->y = is_numeric($y) ? intval($y) : $this->y; - } - - /** - * Set current line color - * - * @param string $color - * @return void - */ - public function color($color) - { - $this->color = $color; - } - - /** - * Set current line width in pixels - * - * @param int $width - * @return void - */ - public function width($width) - { - throw new \Intervention\Image\Exception\NotSupportedException( - "Line width is not supported by GD driver." - ); - } - - /** - * Draw current instance of line to given endpoint on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $color = new Color($this->color); - imageline($image->getCore(), $x, $y, $this->x, $this->y, $color->getInt()); - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Shapes/PolygonShape.php b/src/Intervention/Image/Gd/Shapes/PolygonShape.php deleted file mode 100644 index 5e14df40..00000000 --- a/src/Intervention/Image/Gd/Shapes/PolygonShape.php +++ /dev/null @@ -1,49 +0,0 @@ -points = $points; - } - - /** - * Draw polygon on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $background = new Color($this->background); - imagefilledpolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $background->getInt()); - - if ($this->hasBorder()) { - $border_color = new Color($this->border_color); - imagesetthickness($image->getCore(), $this->border_width); - imagepolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $border_color->getInt()); - } - - return true; - } -} diff --git a/src/Intervention/Image/Gd/Shapes/RectangleShape.php b/src/Intervention/Image/Gd/Shapes/RectangleShape.php deleted file mode 100644 index 5f69a7f9..00000000 --- a/src/Intervention/Image/Gd/Shapes/RectangleShape.php +++ /dev/null @@ -1,76 +0,0 @@ -x1 = is_numeric($x1) ? intval($x1) : $this->x1; - $this->y1 = is_numeric($y1) ? intval($y1) : $this->y1; - $this->x2 = is_numeric($x2) ? intval($x2) : $this->x2; - $this->y2 = is_numeric($y2) ? intval($y2) : $this->y2; - } - - /** - * Draw rectangle to given image at certain position - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $background = new Color($this->background); - imagefilledrectangle($image->getCore(), $this->x1, $this->y1, $this->x2, $this->y2, $background->getInt()); - - if ($this->hasBorder()) { - $border_color = new Color($this->border_color); - imagesetthickness($image->getCore(), $this->border_width); - imagerectangle($image->getCore(), $this->x1, $this->y1, $this->x2, $this->y2, $border_color->getInt()); - } - - return true; - } -} diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php deleted file mode 100644 index 7d5a59b7..00000000 --- a/src/Intervention/Image/Image.php +++ /dev/null @@ -1,370 +0,0 @@ -driver = $driver; - $this->core = $core; - } - - /** - * Magic method to catch all image calls - * usually any AbstractCommand - * - * @param string $name - * @param Array $arguments - * @return mixed - */ - public function __call($name, $arguments) - { - $command = $this->driver->executeCommand($this, $name, $arguments); - return $command->hasOutput() ? $command->getOutput() : $this; - } - - /** - * Starts encoding of current image - * - * @param string $format - * @param int $quality - * @return \Intervention\Image\Image - */ - public function encode($format = null, $quality = 90) - { - return $this->driver->encode($this, $format, $quality); - } - - /** - * Saves encoded image in filesystem - * - * @param string $path - * @param int $quality - * @param string $format - * @return \Intervention\Image\Image - */ - public function save($path = null, $quality = null, $format = null) - { - $path = is_null($path) ? $this->basePath() : $path; - - if (is_null($path)) { - throw new NotWritableException( - "Can't write to undefined path." - ); - } - - if ($format === null) { - $format = pathinfo($path, PATHINFO_EXTENSION); - } - - $data = $this->encode($format, $quality); - $saved = @file_put_contents($path, $data); - - if ($saved === false) { - throw new NotWritableException( - "Can't write image data to path ({$path})" - ); - } - - // set new file info - $this->setFileInfoFromPath($path); - - return $this; - } - - /** - * Runs a given filter on current image - * - * @param FiltersFilterInterface $filter - * @return \Intervention\Image\Image - */ - public function filter(Filters\FilterInterface $filter) - { - return $filter->applyFilter($this); - } - - /** - * Returns current image driver - * - * @return \Intervention\Image\AbstractDriver - */ - public function getDriver() - { - return $this->driver; - } - - /** - * Sets current image driver - * @param AbstractDriver $driver - */ - public function setDriver(AbstractDriver $driver) - { - $this->driver = $driver; - - return $this; - } - - /** - * Returns current image resource/obj - * - * @return mixed - */ - public function getCore() - { - return $this->core; - } - - /** - * Sets current image resource - * - * @param mixed $core - */ - public function setCore($core) - { - $this->core = $core; - - return $this; - } - - /** - * Returns current image backup - * - * @param string $name - * @return mixed - */ - public function getBackup($name = null) - { - $name = is_null($name) ? 'default' : $name; - - if ( ! $this->backupExists($name)) { - throw new RuntimeException( - "Backup with name ({$name}) not available. Call backup() before reset()." - ); - } - - return $this->backups[$name]; - } - - /** - * Returns all backups attached to image - * - * @return array - */ - public function getBackups() - { - return $this->backups; - } - - /** - * Sets current image backup - * - * @param mixed $resource - * @param string $name - * @return self - */ - public function setBackup($resource, $name = null) - { - $name = is_null($name) ? 'default' : $name; - - $this->backups[$name] = $resource; - - return $this; - } - - /** - * Checks if named backup exists - * - * @param string $name - * @return bool - */ - private function backupExists($name) - { - return array_key_exists($name, $this->backups); - } - - /** - * Checks if current image is already encoded - * - * @return boolean - */ - public function isEncoded() - { - return ! empty($this->encoded); - } - - /** - * Returns encoded image data of current image - * - * @return string - */ - public function getEncoded() - { - return $this->encoded; - } - - /** - * Sets encoded image buffer - * - * @param string $value - */ - public function setEncoded($value) - { - $this->encoded = $value; - - return $this; - } - - /** - * Calculates current image width - * - * @return int - */ - public function getWidth() - { - return $this->getSize()->width; - } - - /** - * Alias of getWidth() - * - * @return int - */ - public function width() - { - return $this->getWidth(); - } - - /** - * Calculates current image height - * - * @return int - */ - public function getHeight() - { - return $this->getSize()->height; - } - - /** - * Alias of getHeight - * - * @return int - */ - public function height() - { - return $this->getHeight(); - } - - /** - * Reads mime type - * - * @return string - */ - public function mime() - { - return $this->mime; - } - - /** - * Returns encoded image data in string conversion - * - * @return string - */ - public function __toString() - { - return $this->encoded; - } - - /** - * Cloning an image - */ - public function __clone() - { - $this->core = $this->driver->cloneCore($this->core); - } -} diff --git a/src/Intervention/Image/ImageManager.php b/src/Intervention/Image/ImageManager.php deleted file mode 100644 index 324fe7fa..00000000 --- a/src/Intervention/Image/ImageManager.php +++ /dev/null @@ -1,142 +0,0 @@ - 'gd' - ]; - - /** - * Creates new instance of Image Manager - * - * @param array $config - */ - public function __construct(array $config = []) - { - $this->checkRequirements(); - $this->configure($config); - } - - /** - * Overrides configuration settings - * - * @param array $config - * - * @return self - */ - public function configure(array $config = []) - { - $this->config = array_replace($this->config, $config); - - return $this; - } - - /** - * Initiates an Image instance from different input types - * - * @param mixed $data - * - * @return \Intervention\Image\Image - */ - public function make($data) - { - return $this->createDriver()->init($data); - } - - /** - * Creates an empty image canvas - * - * @param int $width - * @param int $height - * @param mixed $background - * - * @return \Intervention\Image\Image - */ - public function canvas($width, $height, $background = null) - { - return $this->createDriver()->newImage($width, $height, $background); - } - - /** - * Create new cached image and run callback - * (requires additional package intervention/imagecache) - * - * @param Closure $callback - * @param int $lifetime - * @param boolean $returnObj - * - * @return Image - */ - public function cache(Closure $callback, $lifetime = null, $returnObj = false) - { - if (class_exists('Intervention\\Image\\ImageCache')) { - // create imagecache - $imagecache = new ImageCache($this); - - // run callback - if (is_callable($callback)) { - $callback($imagecache); - } - - return $imagecache->get($lifetime, $returnObj); - } - - throw new MissingDependencyException( - "Please install package intervention/imagecache before running this function." - ); - } - - /** - * Creates a driver instance according to config settings - * - * @return \Intervention\Image\AbstractDriver - */ - private function createDriver() - { - if (is_string($this->config['driver'])) { - $drivername = ucfirst($this->config['driver']); - $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername); - - if (class_exists($driverclass)) { - return new $driverclass; - } - - throw new NotSupportedException( - "Driver ({$drivername}) could not be instantiated." - ); - } - - if ($this->config['driver'] instanceof AbstractDriver) { - return $this->config['driver']; - } - - throw new NotSupportedException( - "Unknown driver type." - ); - } - - /** - * Check if all requirements are available - * - * @return void - */ - private function checkRequirements() - { - if ( ! function_exists('finfo_buffer')) { - throw new MissingDependencyException( - "PHP Fileinfo extension must be installed/enabled to use Intervention Image." - ); - } - } -} diff --git a/src/Intervention/Image/ImageManagerStatic.php b/src/Intervention/Image/ImageManagerStatic.php deleted file mode 100644 index a1b56426..00000000 --- a/src/Intervention/Image/ImageManagerStatic.php +++ /dev/null @@ -1,88 +0,0 @@ -configure($config); - } - - /** - * Statically initiates an Image instance from different input types - * - * @param mixed $data - * - * @return \Intervention\Image\Image - * @throws \Intervention\Image\Exception\NotReadableException - */ - public static function make($data) - { - return self::getManager()->make($data); - } - - /** - * Statically creates an empty image canvas - * - * @param int $width - * @param int $height - * @param mixed $background - * - * @return \Intervention\Image\Image - */ - public static function canvas($width, $height, $background = null) - { - return self::getManager()->canvas($width, $height, $background); - } - - /** - * Create new cached image and run callback statically - * - * @param Closure $callback - * @param int $lifetime - * @param boolean $returnObj - * - * @return mixed - */ - public static function cache(Closure $callback, $lifetime = null, $returnObj = false) - { - return self::getManager()->cache($callback, $lifetime, $returnObj); - } -} diff --git a/src/Intervention/Image/ImageServiceProvider.php b/src/Intervention/Image/ImageServiceProvider.php deleted file mode 100644 index f99fe4a3..00000000 --- a/src/Intervention/Image/ImageServiceProvider.php +++ /dev/null @@ -1,87 +0,0 @@ -provider = $this->getProvider(); - } - - /** - * Bootstrap the application events. - * - * @return void - */ - public function boot() - { - if (method_exists($this->provider, 'boot')) { - return $this->provider->boot(); - } - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - return $this->provider->register(); - } - - /** - * Return ServiceProvider according to Laravel version - * - * @return \Intervention\Image\Provider\ProviderInterface - */ - private function getProvider() - { - if ($this->app instanceof LumenApplication) { - $provider = '\Intervention\Image\ImageServiceProviderLumen'; - } elseif (version_compare(IlluminateApplication::VERSION, '5.0', '<')) { - $provider = '\Intervention\Image\ImageServiceProviderLaravel4'; - } else { - $provider = '\Intervention\Image\ImageServiceProviderLaravelRecent'; - } - - return new $provider($this->app); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return ['image']; - } -} diff --git a/src/Intervention/Image/ImageServiceProviderLaravel4.php b/src/Intervention/Image/ImageServiceProviderLaravel4.php deleted file mode 100755 index 3b1388f2..00000000 --- a/src/Intervention/Image/ImageServiceProviderLaravel4.php +++ /dev/null @@ -1,112 +0,0 @@ -package('intervention/image'); - - // try to create imagecache route only if imagecache is present - if (class_exists('Intervention\\Image\\ImageCache')) { - - $app = $this->app; - - // load imagecache config - $app['config']->package('intervention/imagecache', __DIR__.'/../../../../imagecache/src/config', 'imagecache'); - $config = $app['config']; - - // create dynamic manipulation route - if (is_string($config->get('imagecache::route'))) { - - // add original to route templates - $config->set('imagecache::templates.original', null); - - // setup image manipulator route - $app['router']->get($config->get('imagecache::route').'/{template}/{filename}', ['as' => 'imagecache', function ($template, $filename) use ($app, $config) { - - // disable session cookies for image route - $app['config']->set('session.driver', 'array'); - - // find file - foreach ($config->get('imagecache::paths') as $path) { - // don't allow '..' in filenames - $image_path = $path.'/'.str_replace('..', '', $filename); - if (file_exists($image_path) && is_file($image_path)) { - break; - } else { - $image_path = false; - } - } - - // abort if file not found - if ($image_path === false) { - $app->abort(404); - } - - // define template callback - $callback = $config->get("imagecache::templates.{$template}"); - - if (is_callable($callback) || class_exists($callback)) { - - // image manipulation based on callback - $content = $app['image']->cache(function ($image) use ($image_path, $callback) { - - switch (true) { - case is_callable($callback): - return $callback($image->make($image_path)); - break; - - case class_exists($callback): - return $image->make($image_path)->filter(new $callback); - break; - } - - }, $config->get('imagecache::lifetime')); - - } else { - - // get original image file contents - $content = file_get_contents($image_path); - } - - // define mime type - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content); - - // return http response - return new IlluminateResponse($content, 200, [ - 'Content-Type' => $mime, - 'Cache-Control' => 'max-age='.($config->get('imagecache::lifetime')*60).', public', - 'Etag' => md5($content) - ]); - - }])->where(['template' => join('|', array_keys($config->get('imagecache::templates'))), 'filename' => '[ \w\\.\\/\\-]+']); - } - } - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $app = $this->app; - - $app['image'] = $app->share(function ($app) { - return new ImageManager($app['config']->get('image::config')); - }); - - $app->alias('image', 'Intervention\Image\ImageManager'); - } -} diff --git a/src/Intervention/Image/ImageServiceProviderLaravelRecent.php b/src/Intervention/Image/ImageServiceProviderLaravelRecent.php deleted file mode 100644 index 17a84d0a..00000000 --- a/src/Intervention/Image/ImageServiceProviderLaravelRecent.php +++ /dev/null @@ -1,106 +0,0 @@ -publishes([ - __DIR__.'/../../config/config.php' => config_path('image.php') - ]); - - // setup intervention/imagecache if package is installed - $this->cacheIsInstalled() ? $this->bootstrapImageCache() : null; - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $app = $this->app; - - // merge default config - $this->mergeConfigFrom( - __DIR__.'/../../config/config.php', - 'image' - ); - - // create image - $app->singleton('image', function ($app) { - return new ImageManager($this->getImageConfig($app)); - }); - - $app->alias('image', 'Intervention\Image\ImageManager'); - } - - /** - * Bootstrap imagecache - * - * @return void - */ - protected function bootstrapImageCache() - { - $app = $this->app; - $config = __DIR__.'/../../../../imagecache/src/config/config.php'; - - $this->publishes([ - $config => config_path('imagecache.php') - ]); - - // merge default config - $this->mergeConfigFrom( - $config, - 'imagecache' - ); - - // imagecache route - if (is_string(config('imagecache.route'))) { - - $filename_pattern = '[ \w\\.\\/\\-\\@\(\)\=]+'; - - // route to access template applied image file - $app['router']->get(config('imagecache.route').'/{template}/{filename}', [ - 'uses' => 'Intervention\Image\ImageCacheController@getResponse', - 'as' => 'imagecache' - ])->where(['filename' => $filename_pattern]); - } - } - - /** - * Return image configuration as array - * - * @param Application $app - * @return array - */ - private function getImageConfig($app) - { - $config = $app['config']->get('image'); - - if (is_null($config)) { - return []; - } - - return $config; - } -} diff --git a/src/Intervention/Image/ImageServiceProviderLeague.php b/src/Intervention/Image/ImageServiceProviderLeague.php deleted file mode 100644 index b756a61f..00000000 --- a/src/Intervention/Image/ImageServiceProviderLeague.php +++ /dev/null @@ -1,42 +0,0 @@ -config = $config; - } - - /** - * Register the server provider. - * - * @return void - */ - public function register() - { - $this->getContainer()->share('Intervention\Image\ImageManager', function () { - return new ImageManager($this->config); - }); - } -} diff --git a/src/Intervention/Image/ImageServiceProviderLumen.php b/src/Intervention/Image/ImageServiceProviderLumen.php deleted file mode 100644 index 4a381ccd..00000000 --- a/src/Intervention/Image/ImageServiceProviderLumen.php +++ /dev/null @@ -1,34 +0,0 @@ -app; - - // merge default config - $this->mergeConfigFrom( - __DIR__.'/../../config/config.php', - 'image' - ); - - // set configuration - $app->configure('image'); - - // create image - $app->singleton('image',function ($app) { - return new ImageManager($app['config']->get('image')); - }); - - $app->alias('image', 'Intervention\Image\ImageManager'); - } -} diff --git a/src/Intervention/Image/Imagick/Color.php b/src/Intervention/Image/Imagick/Color.php deleted file mode 100644 index a41ff3a6..00000000 --- a/src/Intervention/Image/Imagick/Color.php +++ /dev/null @@ -1,279 +0,0 @@ -> 24) & 0xFF; - $r = ($value >> 16) & 0xFF; - $g = ($value >> 8) & 0xFF; - $b = $value & 0xFF; - $a = $this->rgb2alpha($a); - - $this->setPixel($r, $g, $b, $a); - } - - /** - * Initiates color object from given array - * - * @param array $value - * @return \Intervention\Image\AbstractColor - */ - public function initFromArray($array) - { - $array = array_values($array); - - if (count($array) == 4) { - - // color array with alpha value - list($r, $g, $b, $a) = $array; - - } elseif (count($array) == 3) { - - // color array without alpha value - list($r, $g, $b) = $array; - $a = 1; - } - - $this->setPixel($r, $g, $b, $a); - } - - /** - * Initiates color object from given string - * - * @param string $value - * - * @return \Intervention\Image\AbstractColor - */ - public function initFromString($value) - { - if ($color = $this->rgbaFromString($value)) { - $this->setPixel($color[0], $color[1], $color[2], $color[3]); - } - } - - /** - * Initiates color object from given ImagickPixel object - * - * @param ImagickPixel $value - * - * @return \Intervention\Image\AbstractColor - */ - public function initFromObject($value) - { - if (is_a($value, '\ImagickPixel')) { - $this->pixel = $value; - } - } - - /** - * Initiates color object from given R, G and B values - * - * @param int $r - * @param int $g - * @param int $b - * - * @return \Intervention\Image\AbstractColor - */ - public function initFromRgb($r, $g, $b) - { - $this->setPixel($r, $g, $b); - } - - /** - * Initiates color object from given R, G, B and A values - * - * @param int $r - * @param int $g - * @param int $b - * @param float $a - * - * @return \Intervention\Image\AbstractColor - */ - public function initFromRgba($r, $g, $b, $a) - { - $this->setPixel($r, $g, $b, $a); - } - - /** - * Calculates integer value of current color instance - * - * @return int - */ - public function getInt() - { - $r = $this->getRedValue(); - $g = $this->getGreenValue(); - $b = $this->getBlueValue(); - $a = intval(round($this->getAlphaValue() * 255)); - - return intval(($a << 24) + ($r << 16) + ($g << 8) + $b); - } - - /** - * Calculates hexadecimal value of current color instance - * - * @param string $prefix - * - * @return string - */ - public function getHex($prefix = '') - { - return sprintf('%s%02x%02x%02x', $prefix, - $this->getRedValue(), - $this->getGreenValue(), - $this->getBlueValue() - ); - } - - /** - * Calculates RGB(A) in array format of current color instance - * - * @return array - */ - public function getArray() - { - return [ - $this->getRedValue(), - $this->getGreenValue(), - $this->getBlueValue(), - $this->getAlphaValue() - ]; - } - - /** - * Calculates RGBA in string format of current color instance - * - * @return string - */ - public function getRgba() - { - return sprintf('rgba(%d, %d, %d, %.2F)', - $this->getRedValue(), - $this->getGreenValue(), - $this->getBlueValue(), - $this->getAlphaValue() - ); - } - - /** - * Determines if current color is different from given color - * - * @param AbstractColor $color - * @param int $tolerance - * @return boolean - */ - public function differs(AbstractColor $color, $tolerance = 0) - { - $color_tolerance = round($tolerance * 2.55); - $alpha_tolerance = round($tolerance); - - $delta = [ - 'r' => abs($color->getRedValue() - $this->getRedValue()), - 'g' => abs($color->getGreenValue() - $this->getGreenValue()), - 'b' => abs($color->getBlueValue() - $this->getBlueValue()), - 'a' => abs($color->getAlphaValue() - $this->getAlphaValue()) - ]; - - return ( - $delta['r'] > $color_tolerance or - $delta['g'] > $color_tolerance or - $delta['b'] > $color_tolerance or - $delta['a'] > $alpha_tolerance - ); - } - - /** - * Returns RGB red value of current color - * - * @return int - */ - public function getRedValue() - { - return intval(round($this->pixel->getColorValue(\Imagick::COLOR_RED) * 255)); - } - - /** - * Returns RGB green value of current color - * - * @return int - */ - public function getGreenValue() - { - return intval(round($this->pixel->getColorValue(\Imagick::COLOR_GREEN) * 255)); - } - - /** - * Returns RGB blue value of current color - * - * @return int - */ - public function getBlueValue() - { - return intval(round($this->pixel->getColorValue(\Imagick::COLOR_BLUE) * 255)); - } - - /** - * Returns RGB alpha value of current color - * - * @return float - */ - public function getAlphaValue() - { - return round($this->pixel->getColorValue(\Imagick::COLOR_ALPHA), 2); - } - - /** - * Initiates ImagickPixel from given RGBA values - * - * @return \ImagickPixel - */ - private function setPixel($r, $g, $b, $a = null) - { - $a = is_null($a) ? 1 : $a; - - return $this->pixel = new \ImagickPixel( - sprintf('rgba(%d, %d, %d, %.2F)', $r, $g, $b, $a) - ); - } - - /** - * Returns current color as ImagickPixel - * - * @return \ImagickPixel - */ - public function getPixel() - { - return $this->pixel; - } - - /** - * Calculates RGA integer alpha value into float value - * - * @param int $value - * @return float - */ - private function rgb2alpha($value) - { - // (255 -> 1.0) / (0 -> 0.0) - return (float) round($value/255, 2); - } - -} diff --git a/src/Intervention/Image/Imagick/Commands/BackupCommand.php b/src/Intervention/Image/Imagick/Commands/BackupCommand.php deleted file mode 100644 index 76b4f72b..00000000 --- a/src/Intervention/Image/Imagick/Commands/BackupCommand.php +++ /dev/null @@ -1,25 +0,0 @@ -argument(0)->value(); - - // clone current image resource - $clone = clone $image; - $image->setBackup($clone->getCore(), $backupName); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/BlurCommand.php b/src/Intervention/Image/Imagick/Commands/BlurCommand.php deleted file mode 100644 index d2533e0e..00000000 --- a/src/Intervention/Image/Imagick/Commands/BlurCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(0, 100)->value(1); - - return $image->getCore()->blurImage(1 * $amount, 0.5 * $amount); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php b/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php deleted file mode 100644 index 03ac8478..00000000 --- a/src/Intervention/Image/Imagick/Commands/BrightnessCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - - return $image->getCore()->modulateImage(100 + $level, 100, 100); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php b/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php deleted file mode 100644 index 3a6506f6..00000000 --- a/src/Intervention/Image/Imagick/Commands/ColorizeCommand.php +++ /dev/null @@ -1,44 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - $green = $this->argument(1)->between(-100, 100)->required()->value(); - $blue = $this->argument(2)->between(-100, 100)->required()->value(); - - // normalize colorize levels - $red = $this->normalizeLevel($red); - $green = $this->normalizeLevel($green); - $blue = $this->normalizeLevel($blue); - - $qrange = $image->getCore()->getQuantumRange(); - - // apply - $image->getCore()->levelImage(0, $red, $qrange['quantumRangeLong'], \Imagick::CHANNEL_RED); - $image->getCore()->levelImage(0, $green, $qrange['quantumRangeLong'], \Imagick::CHANNEL_GREEN); - $image->getCore()->levelImage(0, $blue, $qrange['quantumRangeLong'], \Imagick::CHANNEL_BLUE); - - return true; - } - - private function normalizeLevel($level) - { - if ($level > 0) { - return $level/5; - } else { - return ($level+100)/100; - } - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ContrastCommand.php b/src/Intervention/Image/Imagick/Commands/ContrastCommand.php deleted file mode 100644 index c4847c61..00000000 --- a/src/Intervention/Image/Imagick/Commands/ContrastCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(-100, 100)->required()->value(); - - return $image->getCore()->sigmoidalContrastImage($level > 0, $level / 4, 0); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/CropCommand.php b/src/Intervention/Image/Imagick/Commands/CropCommand.php deleted file mode 100644 index 618edea7..00000000 --- a/src/Intervention/Image/Imagick/Commands/CropCommand.php +++ /dev/null @@ -1,45 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->required()->value(); - $x = $this->argument(2)->type('digit')->value(); - $y = $this->argument(3)->type('digit')->value(); - - if (is_null($width) || is_null($height)) { - throw new InvalidArgumentException( - "Width and height of cutout needs to be defined." - ); - } - - $cropped = new Size($width, $height); - $position = new Point($x, $y); - - // align boxes - if (is_null($x) && is_null($y)) { - $position = $image->getSize()->align('center')->relativePosition($cropped->align('center')); - } - - // crop image core - $image->getCore()->cropImage($cropped->width, $cropped->height, $position->x, $position->y); - $image->getCore()->setImagePage(0,0,0,0); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/DestroyCommand.php b/src/Intervention/Image/Imagick/Commands/DestroyCommand.php deleted file mode 100644 index 58c9556e..00000000 --- a/src/Intervention/Image/Imagick/Commands/DestroyCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -getCore()->clear(); - - // destroy backups - foreach ($image->getBackups() as $backup) { - $backup->clear(); - } - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ExifCommand.php b/src/Intervention/Image/Imagick/Commands/ExifCommand.php deleted file mode 100644 index 521b38b0..00000000 --- a/src/Intervention/Image/Imagick/Commands/ExifCommand.php +++ /dev/null @@ -1,63 +0,0 @@ -preferExtension = false; - } - - /** - * Read Exif data from the given image - * - * @param \Intervention\Image\Image $image - * @return boolean - */ - public function execute($image) - { - if ($this->preferExtension && function_exists('exif_read_data')) { - return parent::execute($image); - } - - $core = $image->getCore(); - - if ( ! method_exists($core, 'getImageProperties')) { - throw new NotSupportedException( - "Reading Exif data is not supported by this PHP installation." - ); - } - - $requestedKey = $this->argument(0)->value(); - if ($requestedKey !== null) { - $this->setOutput($core->getImageProperty('exif:' . $requestedKey)); - return true; - } - - $exif = []; - $properties = $core->getImageProperties(); - foreach ($properties as $key => $value) { - if (substr($key, 0, 5) !== 'exif:') { - continue; - } - - $exif[substr($key, 5)] = $value; - } - - $this->setOutput($exif); - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/FillCommand.php b/src/Intervention/Image/Imagick/Commands/FillCommand.php deleted file mode 100644 index 82baac53..00000000 --- a/src/Intervention/Image/Imagick/Commands/FillCommand.php +++ /dev/null @@ -1,105 +0,0 @@ -argument(0)->value(); - $x = $this->argument(1)->type('digit')->value(); - $y = $this->argument(2)->type('digit')->value(); - - $imagick = $image->getCore(); - - try { - // set image filling - $source = new Decoder; - $filling = $source->init($filling); - - } catch (NotReadableException $e) { - - // set solid color filling - $filling = new Color($filling); - } - - // flood fill if coordinates are set - if (is_int($x) && is_int($y)) { - - // flood fill with texture - if ($filling instanceof Image) { - - // create tile - $tile = clone $image->getCore(); - - // mask away color at position - $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false); - - // create canvas - $canvas = clone $image->getCore(); - - // fill canvas with texture - $canvas = $canvas->textureImage($filling->getCore()); - - // merge canvas and tile - $canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0); - - // replace image core - $image->setCore($canvas); - - // flood fill with color - } elseif ($filling instanceof Color) { - - // create canvas with filling - $canvas = new \Imagick; - $canvas->newImage($image->getWidth(), $image->getHeight(), $filling->getPixel(), 'png'); - - // create tile to put on top - $tile = clone $image->getCore(); - - // mask away color at pos. - $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false); - - // save alpha channel of original image - $alpha = clone $image->getCore(); - - // merge original with canvas and tile - $image->getCore()->compositeImage($canvas, \Imagick::COMPOSITE_DEFAULT, 0, 0); - $image->getCore()->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0); - - // restore alpha channel of original image - $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); - } - - } else { - - if ($filling instanceof Image) { - - // fill whole image with texture - $image->setCore($image->getCore()->textureImage($filling->getCore())); - - } elseif ($filling instanceof Color) { - - // fill whole image with color - $draw = new \ImagickDraw(); - $draw->setFillColor($filling->getPixel()); - $draw->rectangle(0, 0, $image->getWidth(), $image->getHeight()); - $image->getCore()->drawImage($draw); - } - } - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/FitCommand.php b/src/Intervention/Image/Imagick/Commands/FitCommand.php deleted file mode 100644 index 6d62ba67..00000000 --- a/src/Intervention/Image/Imagick/Commands/FitCommand.php +++ /dev/null @@ -1,42 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->value($width); - $constraints = $this->argument(2)->type('closure')->value(); - $position = $this->argument(3)->type('string')->value('center'); - - // calculate size - $cropped = $image->getSize()->fit(new Size($width, $height), $position); - $resized = clone $cropped; - $resized = $resized->resize($width, $height, $constraints); - - // crop image - $image->getCore()->cropImage( - $cropped->width, - $cropped->height, - $cropped->pivot->x, - $cropped->pivot->y - ); - - // resize image - $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight()); - $image->getCore()->setImagePage(0,0,0,0); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/FlipCommand.php b/src/Intervention/Image/Imagick/Commands/FlipCommand.php deleted file mode 100644 index abae16ad..00000000 --- a/src/Intervention/Image/Imagick/Commands/FlipCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -argument(0)->value('h'); - - if (in_array(strtolower($mode), [2, 'v', 'vert', 'vertical'])) { - // flip vertical - return $image->getCore()->flipImage(); - } else { - // flip horizontal - return $image->getCore()->flopImage(); - } - } -} diff --git a/src/Intervention/Image/Imagick/Commands/GammaCommand.php b/src/Intervention/Image/Imagick/Commands/GammaCommand.php deleted file mode 100644 index 200515f3..00000000 --- a/src/Intervention/Image/Imagick/Commands/GammaCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - - return $image->getCore()->gammaImage($gamma); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/GetSizeCommand.php b/src/Intervention/Image/Imagick/Commands/GetSizeCommand.php deleted file mode 100644 index ccccedb0..00000000 --- a/src/Intervention/Image/Imagick/Commands/GetSizeCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -getCore(); - - $this->setOutput(new Size( - $core->getImageWidth(), - $core->getImageHeight() - )); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/GreyscaleCommand.php b/src/Intervention/Image/Imagick/Commands/GreyscaleCommand.php deleted file mode 100644 index df0ff5b5..00000000 --- a/src/Intervention/Image/Imagick/Commands/GreyscaleCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -getCore()->modulateImage(100, 0, 100); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/HeightenCommand.php b/src/Intervention/Image/Imagick/Commands/HeightenCommand.php deleted file mode 100644 index 0b61e50c..00000000 --- a/src/Intervention/Image/Imagick/Commands/HeightenCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $additionalConstraints = $this->argument(1)->type('closure')->value(); - - $this->arguments[0] = null; - $this->arguments[1] = $height; - $this->arguments[2] = function ($constraint) use ($additionalConstraints) { - $constraint->aspectRatio(); - if(is_callable($additionalConstraints)) - $additionalConstraints($constraint); - }; - - return parent::execute($image); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/InsertCommand.php b/src/Intervention/Image/Imagick/Commands/InsertCommand.php deleted file mode 100644 index 2a997436..00000000 --- a/src/Intervention/Image/Imagick/Commands/InsertCommand.php +++ /dev/null @@ -1,33 +0,0 @@ -argument(0)->required()->value(); - $position = $this->argument(1)->type('string')->value(); - $x = $this->argument(2)->type('digit')->value(0); - $y = $this->argument(3)->type('digit')->value(0); - - // build watermark - $watermark = $image->getDriver()->init($source); - - // define insertion point - $image_size = $image->getSize()->align($position, $x, $y); - $watermark_size = $watermark->getSize()->align($position); - $target = $image_size->relativePosition($watermark_size); - - // insert image at position - return $image->getCore()->compositeImage($watermark->getCore(), \Imagick::COMPOSITE_DEFAULT, $target->x, $target->y); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php b/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php deleted file mode 100644 index 913cab7e..00000000 --- a/src/Intervention/Image/Imagick/Commands/InterlaceCommand.php +++ /dev/null @@ -1,29 +0,0 @@ -argument(0)->type('bool')->value(true); - - if ($mode) { - $mode = \Imagick::INTERLACE_LINE; - } else { - $mode = \Imagick::INTERLACE_NO; - } - - $image->getCore()->setInterlaceScheme($mode); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/InvertCommand.php b/src/Intervention/Image/Imagick/Commands/InvertCommand.php deleted file mode 100644 index 1d134301..00000000 --- a/src/Intervention/Image/Imagick/Commands/InvertCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -getCore()->negateImage(false); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php b/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php deleted file mode 100644 index 16f9b82e..00000000 --- a/src/Intervention/Image/Imagick/Commands/LimitColorsCommand.php +++ /dev/null @@ -1,59 +0,0 @@ -argument(0)->value(); - $matte = $this->argument(1)->value(); - - // get current image size - $size = $image->getSize(); - - // build 2 color alpha mask from original alpha - $alpha = clone $image->getCore(); - $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA); - $alpha->transparentPaintImage('#ffffff', 0, 0, false); - $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA); - $alpha->negateImage(false); - - if ($matte) { - - // get matte color - $mattecolor = $image->getDriver()->parseColor($matte)->getPixel(); - - // create matte image - $canvas = new \Imagick; - $canvas->newImage($size->width, $size->height, $mattecolor, 'png'); - - // lower colors of original and copy to matte - $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false); - $canvas->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0); - - // copy new alpha to canvas - $canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); - - // replace core - $image->setCore($canvas); - - } else { - - $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false); - $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); - - } - - return true; - - } -} diff --git a/src/Intervention/Image/Imagick/Commands/MaskCommand.php b/src/Intervention/Image/Imagick/Commands/MaskCommand.php deleted file mode 100644 index af9d6b2f..00000000 --- a/src/Intervention/Image/Imagick/Commands/MaskCommand.php +++ /dev/null @@ -1,60 +0,0 @@ -argument(0)->value(); - $mask_w_alpha = $this->argument(1)->type('bool')->value(false); - - // get imagick - $imagick = $image->getCore(); - - // build mask image from source - $mask = $image->getDriver()->init($mask_source); - - // resize mask to size of current image (if necessary) - $image_size = $image->getSize(); - if ($mask->getSize() != $image_size) { - $mask->resize($image_size->width, $image_size->height); - } - - $imagick->setImageMatte(true); - - if ($mask_w_alpha) { - - // just mask with alpha map - $imagick->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DSTIN, 0, 0); - - } else { - - // get alpha channel of original as greyscale image - $original_alpha = clone $imagick; - $original_alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA); - - // use red channel from mask ask alpha - $mask_alpha = clone $mask->getCore(); - $mask_alpha->compositeImage($mask->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0); - // $mask_alpha->setImageAlphaChannel(\Imagick::ALPHACHANNEL_DEACTIVATE); - $mask_alpha->separateImageChannel(\Imagick::CHANNEL_ALL); - - // combine both alphas from original and mask - $original_alpha->compositeImage($mask_alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); - - // mask the image with the alpha combination - $imagick->compositeImage($original_alpha, \Imagick::COMPOSITE_DSTIN, 0, 0); - } - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/OpacityCommand.php b/src/Intervention/Image/Imagick/Commands/OpacityCommand.php deleted file mode 100644 index b4708d89..00000000 --- a/src/Intervention/Image/Imagick/Commands/OpacityCommand.php +++ /dev/null @@ -1,23 +0,0 @@ -argument(0)->between(0, 100)->required()->value(); - - $transparency = $transparency > 0 ? (100 / $transparency) : 1000; - - return $image->getCore()->evaluateImage(\Imagick::EVALUATE_DIVIDE, $transparency, \Imagick::CHANNEL_ALPHA); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/PickColorCommand.php b/src/Intervention/Image/Imagick/Commands/PickColorCommand.php deleted file mode 100644 index 978a1284..00000000 --- a/src/Intervention/Image/Imagick/Commands/PickColorCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $y = $this->argument(1)->type('digit')->required()->value(); - $format = $this->argument(2)->type('string')->value('array'); - - // pick color - $color = new Color($image->getCore()->getImagePixelColor($x, $y)); - - // format to output - $this->setOutput($color->format($format)); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/PixelCommand.php b/src/Intervention/Image/Imagick/Commands/PixelCommand.php deleted file mode 100644 index 6eb6ae71..00000000 --- a/src/Intervention/Image/Imagick/Commands/PixelCommand.php +++ /dev/null @@ -1,31 +0,0 @@ -argument(0)->required()->value(); - $color = new Color($color); - $x = $this->argument(1)->type('digit')->required()->value(); - $y = $this->argument(2)->type('digit')->required()->value(); - - // prepare pixel - $draw = new \ImagickDraw; - $draw->setFillColor($color->getPixel()); - $draw->point($x, $y); - - // apply pixel - return $image->getCore()->drawImage($draw); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/PixelateCommand.php b/src/Intervention/Image/Imagick/Commands/PixelateCommand.php deleted file mode 100644 index 6fe79491..00000000 --- a/src/Intervention/Image/Imagick/Commands/PixelateCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -argument(0)->type('digit')->value(10); - - $width = $image->getWidth(); - $height = $image->getHeight(); - - $image->getCore()->scaleImage(max(1, ($width / $size)), max(1, ($height / $size))); - $image->getCore()->scaleImage($width, $height); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ResetCommand.php b/src/Intervention/Image/Imagick/Commands/ResetCommand.php deleted file mode 100644 index 77b7f336..00000000 --- a/src/Intervention/Image/Imagick/Commands/ResetCommand.php +++ /dev/null @@ -1,40 +0,0 @@ -argument(0)->value(); - - $backup = $image->getBackup($backupName); - - if ($backup instanceof \Imagick) { - - // destroy current core - $image->getCore()->clear(); - - // clone backup - $backup = clone $backup; - - // reset to new resource - $image->setCore($backup); - - return true; - } - - throw new RuntimeException( - "Backup not available. Call backup({$backupName}) before reset()." - ); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php b/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php deleted file mode 100644 index ecf07610..00000000 --- a/src/Intervention/Image/Imagick/Commands/ResizeCanvasCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $height = $this->argument(1)->type('digit')->required()->value(); - $anchor = $this->argument(2)->value('center'); - $relative = $this->argument(3)->type('boolean')->value(false); - $bgcolor = $this->argument(4)->value(); - - $original_width = $image->getWidth(); - $original_height = $image->getHeight(); - - // check of only width or height is set - $width = is_null($width) ? $original_width : intval($width); - $height = is_null($height) ? $original_height : intval($height); - - // check on relative width/height - if ($relative) { - $width = $original_width + $width; - $height = $original_height + $height; - } - - // check for negative width/height - $width = ($width <= 0) ? $width + $original_width : $width; - $height = ($height <= 0) ? $height + $original_height : $height; - - // create new canvas - $canvas = $image->getDriver()->newImage($width, $height, $bgcolor); - - // set copy position - $canvas_size = $canvas->getSize()->align($anchor); - $image_size = $image->getSize()->align($anchor); - $canvas_pos = $image_size->relativePosition($canvas_size); - $image_pos = $canvas_size->relativePosition($image_size); - - if ($width <= $original_width) { - $dst_x = 0; - $src_x = $canvas_pos->x; - $src_w = $canvas_size->width; - } else { - $dst_x = $image_pos->x; - $src_x = 0; - $src_w = $original_width; - } - - if ($height <= $original_height) { - $dst_y = 0; - $src_y = $canvas_pos->y; - $src_h = $canvas_size->height; - } else { - $dst_y = $image_pos->y; - $src_y = 0; - $src_h = $original_height; - } - - // make image area transparent to keep transparency - // even if background-color is set - $rect = new \ImagickDraw; - $fill = $canvas->pickColor(0, 0, 'hex'); - $fill = $fill == '#ff0000' ? '#00ff00' : '#ff0000'; - $rect->setFillColor($fill); - $rect->rectangle($dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1); - $canvas->getCore()->drawImage($rect); - $canvas->getCore()->transparentPaintImage($fill, 0, 0, false); - - $canvas->getCore()->setImageColorspace($image->getCore()->getImageColorspace()); - - // copy image into new canvas - $image->getCore()->cropImage($src_w, $src_h, $src_x, $src_y); - $canvas->getCore()->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y); - $canvas->getCore()->setImagePage(0,0,0,0); - - // set new core to canvas - $image->setCore($canvas->getCore()); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/ResizeCommand.php b/src/Intervention/Image/Imagick/Commands/ResizeCommand.php deleted file mode 100644 index 3d4dc5be..00000000 --- a/src/Intervention/Image/Imagick/Commands/ResizeCommand.php +++ /dev/null @@ -1,29 +0,0 @@ -argument(0)->value(); - $height = $this->argument(1)->value(); - $constraints = $this->argument(2)->type('closure')->value(); - - // resize box - $resized = $image->getSize()->resize($width, $height, $constraints); - - // modify image - $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight()); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/RotateCommand.php b/src/Intervention/Image/Imagick/Commands/RotateCommand.php deleted file mode 100644 index b3e12a53..00000000 --- a/src/Intervention/Image/Imagick/Commands/RotateCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -argument(0)->type('numeric')->required()->value(); - $color = $this->argument(1)->value(); - $color = new Color($color); - - // restrict rotations beyond 360 degrees, since the end result is the same - $angle = fmod($angle, 360); - - // rotate image - $image->getCore()->rotateImage($color->getPixel(), ($angle * -1)); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/SharpenCommand.php b/src/Intervention/Image/Imagick/Commands/SharpenCommand.php deleted file mode 100644 index bc5e393f..00000000 --- a/src/Intervention/Image/Imagick/Commands/SharpenCommand.php +++ /dev/null @@ -1,21 +0,0 @@ -argument(0)->between(0, 100)->value(10); - - return $image->getCore()->unsharpMaskImage(1, 1, $amount / 6.25, 0); - } -} diff --git a/src/Intervention/Image/Imagick/Commands/TrimCommand.php b/src/Intervention/Image/Imagick/Commands/TrimCommand.php deleted file mode 100644 index bdc897be..00000000 --- a/src/Intervention/Image/Imagick/Commands/TrimCommand.php +++ /dev/null @@ -1,121 +0,0 @@ -argument(0)->type('string')->value(); - $away = $this->argument(1)->value(); - $tolerance = $this->argument(2)->type('numeric')->value(0); - $feather = $this->argument(3)->type('numeric')->value(0); - - $width = $image->getWidth(); - $height = $image->getHeight(); - - $checkTransparency = false; - - // define borders to trim away - if (is_null($away)) { - $away = ['top', 'right', 'bottom', 'left']; - } elseif (is_string($away)) { - $away = [$away]; - } - - // lower border names - foreach ($away as $key => $value) { - $away[$key] = strtolower($value); - } - - // define base color position - switch (strtolower($base)) { - case 'transparent': - case 'trans': - $checkTransparency = true; - $base_x = 0; - $base_y = 0; - break; - - case 'bottom-right': - case 'right-bottom': - $base_x = $width - 1; - $base_y = $height - 1; - break; - - default: - case 'top-left': - case 'left-top': - $base_x = 0; - $base_y = 0; - break; - } - - // pick base color - if ($checkTransparency) { - $base_color = new Color; // color will only be used to compare alpha channel - } else { - $base_color = $image->pickColor($base_x, $base_y, 'object'); - } - - // trim on clone to get only coordinates - $trimed = clone $image->getCore(); - - // add border to trim specific color - $trimed->borderImage($base_color->getPixel(), 1, 1); - - // trim image - $trimed->trimImage(65850 / 100 * $tolerance); - - // get coordinates of trim - $imagePage = $trimed->getImagePage(); - list($crop_x, $crop_y) = [$imagePage['x']-1, $imagePage['y']-1]; - // $trimed->setImagePage(0, 0, 0, 0); - list($crop_width, $crop_height) = [$trimed->width, $trimed->height]; - - // adjust settings if right should not be trimed - if ( ! in_array('right', $away)) { - $crop_width = $crop_width + ($width - ($width - $crop_x)); - } - - // adjust settings if bottom should not be trimed - if ( ! in_array('bottom', $away)) { - $crop_height = $crop_height + ($height - ($height - $crop_y)); - } - - // adjust settings if left should not be trimed - if ( ! in_array('left', $away)) { - $crop_width = $crop_width + $crop_x; - $crop_x = 0; - } - - // adjust settings if top should not be trimed - if ( ! in_array('top', $away)) { - $crop_height = $crop_height + $crop_y; - $crop_y = 0; - } - - // add feather - $crop_width = min($width, ($crop_width + $feather * 2)); - $crop_height = min($height, ($crop_height + $feather * 2)); - $crop_x = max(0, ($crop_x - $feather)); - $crop_y = max(0, ($crop_y - $feather)); - - // finally crop based on page - $image->getCore()->cropImage($crop_width, $crop_height, $crop_x, $crop_y); - $image->getCore()->setImagePage(0,0,0,0); - - $trimed->destroy(); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Commands/WidenCommand.php b/src/Intervention/Image/Imagick/Commands/WidenCommand.php deleted file mode 100644 index a1967534..00000000 --- a/src/Intervention/Image/Imagick/Commands/WidenCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -argument(0)->type('digit')->required()->value(); - $additionalConstraints = $this->argument(1)->type('closure')->value(); - - $this->arguments[0] = $width; - $this->arguments[1] = null; - $this->arguments[2] = function ($constraint) use ($additionalConstraints) { - $constraint->aspectRatio(); - if(is_callable($additionalConstraints)) - $additionalConstraints($constraint); - }; - - return parent::execute($image); - } -} diff --git a/src/Intervention/Image/Imagick/Decoder.php b/src/Intervention/Image/Imagick/Decoder.php deleted file mode 100644 index f4dde9a8..00000000 --- a/src/Intervention/Image/Imagick/Decoder.php +++ /dev/null @@ -1,124 +0,0 @@ -setBackgroundColor(new \ImagickPixel('transparent')); - $core->readImage($path); - $core->setImageType(defined('\Imagick::IMGTYPE_TRUECOLORALPHA') ? \Imagick::IMGTYPE_TRUECOLORALPHA : \Imagick::IMGTYPE_TRUECOLORMATTE); - - } catch (\ImagickException $e) { - throw new \Intervention\Image\Exception\NotReadableException( - "Unable to read image from path ({$path}).", - 0, - $e - ); - } - - // build image - $image = $this->initFromImagick($core); - $image->setFileInfoFromPath($path); - - return $image; - } - - /** - * Initiates new image from GD resource - * - * @param Resource $resource - * @return \Intervention\Image\Image - */ - public function initFromGdResource($resource) - { - throw new NotSupportedException( - 'Imagick driver is unable to init from GD resource.' - ); - } - - /** - * Initiates new image from Imagick object - * - * @param Imagick $object - * @return \Intervention\Image\Image - */ - public function initFromImagick(\Imagick $object) - { - // currently animations are not supported - // so all images are turned into static - $object = $this->removeAnimation($object); - - // reset image orientation - $object->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED); - - return new Image(new Driver, $object); - } - - /** - * Initiates new image from binary data - * - * @param string $data - * @return \Intervention\Image\Image - */ - public function initFromBinary($binary) - { - $core = new \Imagick; - - try { - $core->setBackgroundColor(new \ImagickPixel('transparent')); - - $core->readImageBlob($binary); - - } catch (\ImagickException $e) { - throw new NotReadableException( - "Unable to read image from binary data.", - 0, - $e - ); - } - - // build image - $image = $this->initFromImagick($core); - $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary); - - return $image; - } - - /** - * Turns object into one frame Imagick object - * by removing all frames except first - * - * @param Imagick $object - * @return Imagick - */ - private function removeAnimation(\Imagick $object) - { - $imagick = new \Imagick; - - foreach ($object as $frame) { - $imagick->addImage($frame->getImage()); - break; - } - - $object->destroy(); - - return $imagick; - } -} diff --git a/src/Intervention/Image/Imagick/Driver.php b/src/Intervention/Image/Imagick/Driver.php deleted file mode 100644 index bb26ca0f..00000000 --- a/src/Intervention/Image/Imagick/Driver.php +++ /dev/null @@ -1,74 +0,0 @@ -coreAvailable()) { - throw new NotSupportedException( - "ImageMagick module not available with this PHP installation." - ); - } - - $this->decoder = $decoder ? $decoder : new Decoder; - $this->encoder = $encoder ? $encoder : new Encoder; - } - - /** - * Creates new image instance - * - * @param int $width - * @param int $height - * @param mixed $background - * @return \Intervention\Image\Image - */ - public function newImage($width, $height, $background = null) - { - $background = new Color($background); - - // create empty core - $core = new \Imagick; - $core->newImage($width, $height, $background->getPixel(), 'png'); - $core->setType(\Imagick::IMGTYPE_UNDEFINED); - $core->setImageType(\Imagick::IMGTYPE_UNDEFINED); - $core->setColorspace(\Imagick::COLORSPACE_UNDEFINED); - - // build image - $image = new Image(new static, $core); - - return $image; - } - - /** - * Reads given string into color object - * - * @param string $value - * @return AbstractColor - */ - public function parseColor($value) - { - return new Color($value); - } - - /** - * Checks if core module installation is available - * - * @return boolean - */ - protected function coreAvailable() - { - return (extension_loaded('imagick') && class_exists('Imagick')); - } -} diff --git a/src/Intervention/Image/Imagick/Encoder.php b/src/Intervention/Image/Imagick/Encoder.php deleted file mode 100644 index feb8a9d5..00000000 --- a/src/Intervention/Image/Imagick/Encoder.php +++ /dev/null @@ -1,239 +0,0 @@ -image->getCore(); - $imagick->setImageBackgroundColor('white'); - $imagick->setBackgroundColor('white'); - $imagick = $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - $imagick->setCompressionQuality($this->quality); - $imagick->setImageCompressionQuality($this->quality); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as PNG string - * - * @return string - */ - protected function processPng() - { - $format = 'png'; - $compression = \Imagick::COMPRESSION_ZIP; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_PNG); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as GIF string - * - * @return string - */ - protected function processGif() - { - $format = 'gif'; - $compression = \Imagick::COMPRESSION_LZW; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_GIF); - - return $imagick->getImagesBlob(); - } - - protected function processWebp() - { - if ( ! \Imagick::queryFormats('WEBP')) { - throw new NotSupportedException( - "Webp format is not supported by Imagick installation." - ); - } - - $format = 'webp'; - $compression = \Imagick::COMPRESSION_JPEG; - - $imagick = $this->image->getCore(); - $imagick->setImageBackgroundColor(new \ImagickPixel('transparent')); - - $imagick = $imagick->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - $imagick->setImageCompressionQuality($this->quality); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as TIFF string - * - * @return string - */ - protected function processTiff() - { - $format = 'tiff'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - $imagick->setCompressionQuality($this->quality); - $imagick->setImageCompressionQuality($this->quality); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_TIFF_II); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as BMP string - * - * @return string - */ - protected function processBmp() - { - $format = 'bmp'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_BMP); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as ICO string - * - * @return string - */ - protected function processIco() - { - $format = 'ico'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_ICO); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as PSD string - * - * @return string - */ - protected function processPsd() - { - $format = 'psd'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - - $this->image->mime = image_type_to_mime_type(IMAGETYPE_PSD); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as AVIF string - * - * @return string - */ - protected function processAvif() - { - if ( ! \Imagick::queryFormats('AVIF')) { - throw new NotSupportedException( - "AVIF format is not supported by Imagick installation." - ); - } - - $format = 'avif'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - $imagick->setCompressionQuality($this->quality); - $imagick->setImageCompressionQuality($this->quality); - - return $imagick->getImagesBlob(); - } - - /** - * Processes and returns encoded image as HEIC string - * - * @return string - */ - protected function processHeic() - { - if ( ! \Imagick::queryFormats('HEIC')) { - throw new NotSupportedException( - "HEIC format is not supported by Imagick installation." - ); - } - - $format = 'heic'; - $compression = \Imagick::COMPRESSION_UNDEFINED; - - $imagick = $this->image->getCore(); - $imagick->setFormat($format); - $imagick->setImageFormat($format); - $imagick->setCompression($compression); - $imagick->setImageCompression($compression); - $imagick->setCompressionQuality($this->quality); - $imagick->setImageCompressionQuality($this->quality); - - return $imagick->getImagesBlob(); - } -} diff --git a/src/Intervention/Image/Imagick/Font.php b/src/Intervention/Image/Imagick/Font.php deleted file mode 100644 index 9869d067..00000000 --- a/src/Intervention/Image/Imagick/Font.php +++ /dev/null @@ -1,122 +0,0 @@ -setStrokeAntialias(true); - $draw->setTextAntialias(true); - - // set font file - if ($this->hasApplicableFontFile()) { - $draw->setFont($this->file); - } else { - throw new RuntimeException( - "Font file must be provided to apply text to image." - ); - } - - // parse text color - $color = new Color($this->color); - - $draw->setFontSize($this->size); - $draw->setFillColor($color->getPixel()); - $draw->setTextKerning($this->kerning); - - // align horizontal - switch (strtolower($this->align)) { - case 'center': - $align = \Imagick::ALIGN_CENTER; - break; - - case 'right': - $align = \Imagick::ALIGN_RIGHT; - break; - - default: - $align = \Imagick::ALIGN_LEFT; - break; - } - - $draw->setTextAlignment($align); - - // align vertical - if (strtolower($this->valign) != 'bottom') { - - // corrections on y-position - switch (strtolower($this->valign)) { - case 'center': - case 'middle': - // calculate box size - $dimensions = $image->getCore()->queryFontMetrics($draw, $this->text); - $posy = $posy + $dimensions['textHeight'] * 0.65 / 2; - break; - - case 'top': - // calculate box size - $dimensions = $image->getCore()->queryFontMetrics($draw, $this->text, false); - $posy = $posy + $dimensions['characterHeight']; - break; - } - } - - // apply to image - $image->getCore()->annotateImage($draw, $posx, $posy, $this->angle * (-1), $this->text); - } - - /** - * Calculates bounding box of current font setting - * - * @return array - */ - public function getBoxSize() - { - $box = []; - - // build draw object - $draw = new \ImagickDraw(); - $draw->setStrokeAntialias(true); - $draw->setTextAntialias(true); - - // set font file - if ($this->hasApplicableFontFile()) { - $draw->setFont($this->file); - } else { - throw new RuntimeException( - "Font file must be provided to apply text to image." - ); - } - - $draw->setFontSize($this->size); - - $dimensions = (new \Imagick())->queryFontMetrics($draw, $this->text); - - if (strlen($this->text) == 0) { - // no text -> no boxsize - $box['width'] = 0; - $box['height'] = 0; - } else { - // get boxsize - $box['width'] = intval(abs($dimensions['textWidth'])); - $box['height'] = intval(abs($dimensions['textHeight'])); - } - - return $box; - } -} diff --git a/src/Intervention/Image/Imagick/Shapes/CircleShape.php b/src/Intervention/Image/Imagick/Shapes/CircleShape.php deleted file mode 100644 index 24172ea1..00000000 --- a/src/Intervention/Image/Imagick/Shapes/CircleShape.php +++ /dev/null @@ -1,40 +0,0 @@ -width = is_numeric($diameter) ? intval($diameter) : $this->diameter; - $this->height = is_numeric($diameter) ? intval($diameter) : $this->diameter; - $this->diameter = is_numeric($diameter) ? intval($diameter) : $this->diameter; - } - - /** - * Draw current circle on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - return parent::applyToImage($image, $x, $y); - } -} diff --git a/src/Intervention/Image/Imagick/Shapes/EllipseShape.php b/src/Intervention/Image/Imagick/Shapes/EllipseShape.php deleted file mode 100644 index 99694b97..00000000 --- a/src/Intervention/Image/Imagick/Shapes/EllipseShape.php +++ /dev/null @@ -1,66 +0,0 @@ -width = is_numeric($width) ? intval($width) : $this->width; - $this->height = is_numeric($height) ? intval($height) : $this->height; - } - - /** - * Draw ellipse instance on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $circle = new \ImagickDraw; - - // set background - $bgcolor = new Color($this->background); - $circle->setFillColor($bgcolor->getPixel()); - - // set border - if ($this->hasBorder()) { - $border_color = new Color($this->border_color); - $circle->setStrokeWidth($this->border_width); - $circle->setStrokeColor($border_color->getPixel()); - } - - $circle->ellipse($x, $y, $this->width / 2, $this->height / 2, 0, 360); - - $image->getCore()->drawImage($circle); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Shapes/LineShape.php b/src/Intervention/Image/Imagick/Shapes/LineShape.php deleted file mode 100644 index 0d6b3297..00000000 --- a/src/Intervention/Image/Imagick/Shapes/LineShape.php +++ /dev/null @@ -1,94 +0,0 @@ -x = is_numeric($x) ? intval($x) : $this->x; - $this->y = is_numeric($y) ? intval($y) : $this->y; - } - - /** - * Set current line color - * - * @param string $color - * @return void - */ - public function color($color) - { - $this->color = $color; - } - - /** - * Set current line width in pixels - * - * @param int $width - * @return void - */ - public function width($width) - { - $this->width = $width; - } - - /** - * Draw current instance of line to given endpoint on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $line = new \ImagickDraw; - - $color = new Color($this->color); - $line->setStrokeColor($color->getPixel()); - $line->setStrokeWidth($this->width); - - $line->line($this->x, $this->y, $x, $y); - $image->getCore()->drawImage($line); - - return true; - } -} diff --git a/src/Intervention/Image/Imagick/Shapes/PolygonShape.php b/src/Intervention/Image/Imagick/Shapes/PolygonShape.php deleted file mode 100644 index 45f44ad8..00000000 --- a/src/Intervention/Image/Imagick/Shapes/PolygonShape.php +++ /dev/null @@ -1,81 +0,0 @@ -points = $this->formatPoints($points); - } - - /** - * Draw polygon on given image - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $polygon = new \ImagickDraw; - - // set background - $bgcolor = new Color($this->background); - $polygon->setFillColor($bgcolor->getPixel()); - - // set border - if ($this->hasBorder()) { - $border_color = new Color($this->border_color); - $polygon->setStrokeWidth($this->border_width); - $polygon->setStrokeColor($border_color->getPixel()); - } - - $polygon->polygon($this->points); - - $image->getCore()->drawImage($polygon); - - return true; - } - - /** - * Format polygon points to Imagick format - * - * @param Array $points - * @return Array - */ - private function formatPoints($points) - { - $ipoints = []; - $count = 1; - - foreach ($points as $key => $value) { - if ($count%2 === 0) { - $y = $value; - $ipoints[] = ['x' => $x, 'y' => $y]; - } else { - $x = $value; - } - $count++; - } - - return $ipoints; - } -} diff --git a/src/Intervention/Image/Imagick/Shapes/RectangleShape.php b/src/Intervention/Image/Imagick/Shapes/RectangleShape.php deleted file mode 100644 index 1166d77b..00000000 --- a/src/Intervention/Image/Imagick/Shapes/RectangleShape.php +++ /dev/null @@ -1,84 +0,0 @@ -x1 = is_numeric($x1) ? intval($x1) : $this->x1; - $this->y1 = is_numeric($y1) ? intval($y1) : $this->y1; - $this->x2 = is_numeric($x2) ? intval($x2) : $this->x2; - $this->y2 = is_numeric($y2) ? intval($y2) : $this->y2; - } - - /** - * Draw rectangle to given image at certain position - * - * @param Image $image - * @param int $x - * @param int $y - * @return boolean - */ - public function applyToImage(Image $image, $x = 0, $y = 0) - { - $rectangle = new \ImagickDraw; - - // set background - $bgcolor = new Color($this->background); - $rectangle->setFillColor($bgcolor->getPixel()); - - // set border - if ($this->hasBorder()) { - $border_color = new Color($this->border_color); - $rectangle->setStrokeWidth($this->border_width); - $rectangle->setStrokeColor($border_color->getPixel()); - } - - $rectangle->rectangle($this->x1, $this->y1, $this->x2, $this->y2); - - $image->getCore()->drawImage($rectangle); - - return true; - } -} diff --git a/src/Intervention/Image/Point.php b/src/Intervention/Image/Point.php deleted file mode 100644 index d51452e0..00000000 --- a/src/Intervention/Image/Point.php +++ /dev/null @@ -1,64 +0,0 @@ -x = is_numeric($x) ? intval($x) : 0; - $this->y = is_numeric($y) ? intval($y) : 0; - } - - /** - * Sets X coordinate - * - * @param int $x - */ - public function setX($x) - { - $this->x = intval($x); - } - - /** - * Sets Y coordinate - * - * @param int $y - */ - public function setY($y) - { - $this->y = intval($y); - } - - /** - * Sets both X and Y coordinate - * - * @param int $x - * @param int $y - */ - public function setPosition($x, $y) - { - $this->setX($x); - $this->setY($y); - } -} diff --git a/src/Intervention/Image/Response.php b/src/Intervention/Image/Response.php deleted file mode 100644 index 8e794081..00000000 --- a/src/Intervention/Image/Response.php +++ /dev/null @@ -1,78 +0,0 @@ -image = $image; - $this->format = $format ? $format : $image->mime; - $this->quality = $quality ? $quality : 90; - } - - /** - * Builds response according to settings - * - * @return mixed - */ - public function make() - { - $this->image->encode($this->format, $this->quality); - $data = $this->image->getEncoded(); - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); - $length = strlen($data); - - if (function_exists('app') && is_a($app = app(), 'Illuminate\Foundation\Application')) { - - $response = IlluminateResponse::make($data); - $response->header('Content-Type', $mime); - $response->header('Content-Length', $length); - - } elseif (class_exists('\Symfony\Component\HttpFoundation\Response')) { - - $response = SymfonyResponse::create($data); - $response->headers->set('Content-Type', $mime); - $response->headers->set('Content-Length', $length); - - } else { - - header('Content-Type: ' . $mime); - header('Content-Length: ' . $length); - $response = $data; - } - - return $response; - } -} diff --git a/src/Intervention/Image/Size.php b/src/Intervention/Image/Size.php deleted file mode 100644 index f8b6dc8e..00000000 --- a/src/Intervention/Image/Size.php +++ /dev/null @@ -1,374 +0,0 @@ -width = is_numeric($width) ? intval($width) : 1; - $this->height = is_numeric($height) ? intval($height) : 1; - $this->pivot = $pivot ? $pivot : new Point; - } - - /** - * Set the width and height absolutely - * - * @param int $width - * @param int $height - */ - public function set($width, $height) - { - $this->width = $width; - $this->height = $height; - } - - /** - * Set current pivot point - * - * @param Point $point - */ - public function setPivot(Point $point) - { - $this->pivot = $point; - } - - /** - * Get the current width - * - * @return int - */ - public function getWidth() - { - return $this->width; - } - - /** - * Get the current height - * - * @return int - */ - public function getHeight() - { - return $this->height; - } - - /** - * Calculate the current aspect ratio - * - * @return float - */ - public function getRatio() - { - return $this->width / $this->height; - } - - /** - * Resize to desired width and/or height - * - * @param int $width - * @param int $height - * @param Closure $callback - * @return Size - */ - public function resize($width, $height, Closure $callback = null) - { - if (is_null($width) && is_null($height)) { - throw new InvalidArgumentException( - "Width or height needs to be defined." - ); - } - - // new size with dominant width - $dominant_w_size = clone $this; - $dominant_w_size->resizeHeight($height, $callback); - $dominant_w_size->resizeWidth($width, $callback); - - // new size with dominant height - $dominant_h_size = clone $this; - $dominant_h_size->resizeWidth($width, $callback); - $dominant_h_size->resizeHeight($height, $callback); - - // decide which size to use - if ($dominant_h_size->fitsInto(new self($width, $height))) { - $this->set($dominant_h_size->width, $dominant_h_size->height); - } else { - $this->set($dominant_w_size->width, $dominant_w_size->height); - } - - return $this; - } - - /** - * Scale size according to given constraints - * - * @param int $width - * @param Closure $callback - * @return Size - */ - private function resizeWidth($width, Closure $callback = null) - { - $constraint = $this->getConstraint($callback); - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $max_width = $constraint->getSize()->getWidth(); - $max_height = $constraint->getSize()->getHeight(); - } - - if (is_numeric($width)) { - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $this->width = ($width > $max_width) ? $max_width : $width; - } else { - $this->width = $width; - } - - if ($constraint->isFixed(Constraint::ASPECTRATIO)) { - $h = max(1, intval(round($this->width / $constraint->getSize()->getRatio()))); - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $this->height = ($h > $max_height) ? $max_height : $h; - } else { - $this->height = $h; - } - } - } - } - - /** - * Scale size according to given constraints - * - * @param int $height - * @param Closure $callback - * @return Size - */ - private function resizeHeight($height, Closure $callback = null) - { - $constraint = $this->getConstraint($callback); - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $max_width = $constraint->getSize()->getWidth(); - $max_height = $constraint->getSize()->getHeight(); - } - - if (is_numeric($height)) { - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $this->height = ($height > $max_height) ? $max_height : $height; - } else { - $this->height = $height; - } - - if ($constraint->isFixed(Constraint::ASPECTRATIO)) { - $w = max(1, intval(round($this->height * $constraint->getSize()->getRatio()))); - - if ($constraint->isFixed(Constraint::UPSIZE)) { - $this->width = ($w > $max_width) ? $max_width : $w; - } else { - $this->width = $w; - } - } - } - } - - /** - * Calculate the relative position to another Size - * based on the pivot point settings of both sizes. - * - * @param Size $size - * @return \Intervention\Image\Point - */ - public function relativePosition(Size $size) - { - $x = $this->pivot->x - $size->pivot->x; - $y = $this->pivot->y - $size->pivot->y; - - return new Point($x, $y); - } - - /** - * Resize given Size to best fitting size of current size. - * - * @param Size $size - * @return \Intervention\Image\Size - */ - public function fit(Size $size, $position = 'center') - { - // create size with auto height - $auto_height = clone $size; - - $auto_height->resize($this->width, null, function ($constraint) { - $constraint->aspectRatio(); - }); - - // decide which version to use - if ($auto_height->fitsInto($this)) { - - $size = $auto_height; - - } else { - - // create size with auto width - $auto_width = clone $size; - - $auto_width->resize(null, $this->height, function ($constraint) { - $constraint->aspectRatio(); - }); - - $size = $auto_width; - } - - $this->align($position); - $size->align($position); - $size->setPivot($this->relativePosition($size)); - - return $size; - } - - /** - * Checks if given size fits into current size - * - * @param Size $size - * @return boolean - */ - public function fitsInto(Size $size) - { - return ($this->width <= $size->width) && ($this->height <= $size->height); - } - - /** - * Aligns current size's pivot point to given position - * and moves point automatically by offset. - * - * @param string $position - * @param int $offset_x - * @param int $offset_y - * @return \Intervention\Image\Size - */ - public function align($position, $offset_x = 0, $offset_y = 0) - { - switch (strtolower($position)) { - - case 'top': - case 'top-center': - case 'top-middle': - case 'center-top': - case 'middle-top': - $x = intval($this->width / 2); - $y = 0 + $offset_y; - break; - - case 'top-right': - case 'right-top': - $x = $this->width - $offset_x; - $y = 0 + $offset_y; - break; - - case 'left': - case 'left-center': - case 'left-middle': - case 'center-left': - case 'middle-left': - $x = 0 + $offset_x; - $y = intval($this->height / 2); - break; - - case 'right': - case 'right-center': - case 'right-middle': - case 'center-right': - case 'middle-right': - $x = $this->width - $offset_x; - $y = intval($this->height / 2); - break; - - case 'bottom-left': - case 'left-bottom': - $x = 0 + $offset_x; - $y = $this->height - $offset_y; - break; - - case 'bottom': - case 'bottom-center': - case 'bottom-middle': - case 'center-bottom': - case 'middle-bottom': - $x = intval($this->width / 2); - $y = $this->height - $offset_y; - break; - - case 'bottom-right': - case 'right-bottom': - $x = $this->width - $offset_x; - $y = $this->height - $offset_y; - break; - - case 'center': - case 'middle': - case 'center-center': - case 'middle-middle': - $x = intval($this->width / 2) + $offset_x; - $y = intval($this->height / 2) + $offset_y; - break; - - default: - case 'top-left': - case 'left-top': - $x = 0 + $offset_x; - $y = 0 + $offset_y; - break; - } - - $this->pivot->setPosition($x, $y); - - return $this; - } - - /** - * Runs constraints on current size - * - * @param Closure $callback - * @return \Intervention\Image\Constraint - */ - private function getConstraint(Closure $callback = null) - { - $constraint = new Constraint(clone $this); - - if (is_callable($callback)) { - $callback($constraint); - } - - return $constraint; - } -} diff --git a/src/Traits/CanDecodeDataUri.php b/src/Traits/CanDecodeDataUri.php new file mode 100644 index 00000000..350f4096 --- /dev/null +++ b/src/Traits/CanDecodeDataUri.php @@ -0,0 +1,75 @@ +\w+\/[-+.\w]+)?(?P(;[-\w]+=[-\w]+)*)(?P;base64)?,(?P.*)/"; + $result = preg_match($pattern, $value, $matches); + + return new class ($matches, $result) + { + private $matches; + private $result; + + public function __construct($matches, $result) + { + $this->matches = $matches; + $this->result = $result; + } + + public function isValid(): bool + { + return (bool) $this->result; + } + + public function mediaType(): ?string + { + if (isset($this->matches['mediatype']) && !empty($this->matches['mediatype'])) { + return $this->matches['mediatype']; + } + + return null; + } + + public function hasMediaType(): bool + { + return !empty($this->mediaType()); + } + + public function parameters(): array + { + if (isset($this->matches['parameters']) && !empty($this->matches['parameters'])) { + return explode(';', trim($this->matches['parameters'], ';')); + } + + return []; + } + + public function isBase64Encoded(): bool + { + if (isset($this->matches['base64']) && $this->matches['base64'] === ';base64') { + return true; + } + + return false; + } + + public function data(): ?string + { + if (isset($this->matches['data']) && !empty($this->matches['data'])) { + return $this->matches['data']; + } + + return null; + } + }; + } +} diff --git a/src/Traits/CanResolveDriverClass.php b/src/Traits/CanResolveDriverClass.php new file mode 100644 index 00000000..c7447e4f --- /dev/null +++ b/src/Traits/CanResolveDriverClass.php @@ -0,0 +1,48 @@ +getCurrentDriver()), + $classname + ); + + try { + $reflection = new ReflectionClass($classname); + } catch (ReflectionException $e) { + throw new RuntimeException( + 'Class (' . $classname . ') could not be resolved for current driver.' + ); + } + + return $reflection->newInstanceArgs($arguments); + } + + protected function getCurrentDriver() + { + $pattern = '/Intervention\\\Image\\\Drivers\\\(?P[A-Za-z]+)/'; + preg_match($pattern, get_class($this), $matches); + + if (! array_key_exists('driver', $matches)) { + throw new RuntimeException('Current driver could not be resolved.'); + } + + return strtolower($matches['driver']); + } +} diff --git a/src/Traits/CanValidateBase64.php b/src/Traits/CanValidateBase64.php new file mode 100644 index 00000000..7bfe1f21 --- /dev/null +++ b/src/Traits/CanValidateBase64.php @@ -0,0 +1,15 @@ + 4) { + return false; + } + + // validate rgb values + foreach ($input as $value) { + if ($value < 0 || $value > 255) { + return false; + } + } + + // validate alpha value + if ($input[3] > 1 || $input[3] < 0) { + return false; + } + + return true; + } +} diff --git a/src/config/config.php b/src/config/config.php deleted file mode 100644 index 2b1d2c3e..00000000 --- a/src/config/config.php +++ /dev/null @@ -1,20 +0,0 @@ - 'gd' - -]; diff --git a/tests/AbstractColorTest.php b/tests/AbstractColorTest.php deleted file mode 100644 index 0baeaa3b..00000000 --- a/tests/AbstractColorTest.php +++ /dev/null @@ -1,20 +0,0 @@ -getMockForAbstractClass('\Intervention\Image\AbstractColor'); - $color->format('xxxxxxxxxxxxxxxxxxxxxxx'); - } -} diff --git a/tests/AbstractCommandTest.php b/tests/AbstractCommandTest.php deleted file mode 100644 index a89bee49..00000000 --- a/tests/AbstractCommandTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getTestCommand(); - $this->assertEquals('foo', $command->argument(0)->value()); - $this->assertEquals('bar', $command->argument(1)->value()); - } - - public function testGetOutput() - { - $command = $this->getTestCommand(); - $command->setOutput('foo'); - $this->assertEquals('foo', $command->getOutput()); - } - - public function testHasOutput() - { - $command = $this->getTestCommand(); - $this->assertEquals(false, $command->hasOutput()); - $command->setOutput('foo'); - $this->assertEquals(true, $command->hasOutput()); - } - - public function testSetOutput() - { - $command = $this->getTestCommand(); - $command->setOutput('foo'); - $this->assertEquals(true, $command->hasOutput()); - } - - public function getTestCommand() - { - $arguments = ['foo', 'bar']; - $command = $this->getMockForAbstractClass('\Intervention\Image\Commands\AbstractCommand', [$arguments]); - - return $command; - } -} diff --git a/tests/AbstractDecoderTest.php b/tests/AbstractDecoderTest.php deleted file mode 100644 index a06fc8a1..00000000 --- a/tests/AbstractDecoderTest.php +++ /dev/null @@ -1,160 +0,0 @@ -getTestDecoder(new \Imagick); - $this->assertTrue($source->isImagick()); - - $source = $this->getTestDecoder(new stdClass); - $this->assertFalse($source->isImagick()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isImagick()); - } - - public function testIsGdResource() - { - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $source = $this->getTestDecoder($resource); - $this->assertTrue($source->isGdResource()); - - $source = $this->getTestDecoder(tmpfile()); - $this->assertFalse($source->isGdResource()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isGdResource()); - } - - public function testIsFilepath() - { - $source = $this->getTestDecoder(__DIR__.'/AbstractDecoderTest.php'); - $this->assertTrue($source->isFilepath()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isFilepath()); - - $source = $this->getTestDecoder([]); - $this->assertFalse($source->isFilepath()); - - $source = $this->getTestDecoder(new stdClass); - $this->assertFalse($source->isFilepath()); - } - - public function testIsUrl() - { - $source = $this->getTestDecoder('http://foo.bar'); - $this->assertTrue($source->isUrl()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isUrl()); - } - - public function testIsStream() - { - $source = $this->getTestDecoder(fopen(__DIR__ . '/images/test.jpg', 'r')); - $this->assertTrue($source->isStream()); - - $source = $this->getTestDecoder(new \GuzzleHttp\Psr7\Stream(fopen(__DIR__ . '/images/test.jpg', 'r'))); - $this->assertTrue($source->isStream()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isStream()); - } - - public function testIsBinary() - { - $source = $this->getTestDecoder(file_get_contents(__DIR__.'/images/test.jpg')); - $this->assertTrue($source->isBinary()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isBinary()); - - $source = $this->getTestDecoder(1); - $this->assertFalse($source->isBinary()); - - $source = $this->getTestDecoder(0); - $this->assertFalse($source->isBinary()); - - $source = $this->getTestDecoder([1,2,3]); - $this->assertFalse($source->isBinary()); - - $source = $this->getTestDecoder(new stdClass); - $this->assertFalse($source->isBinary()); - } - - public function testIsInterventionImage() - { - $source = $this->getTestDecoder(1); - $this->assertFalse($source->isInterventionImage()); - - $img = Mockery::mock('Intervention\Image\Image'); - $source = $this->getTestDecoder($img); - $this->assertTrue($source->isInterventionImage()); - } - - public function testIsSplFileInfo() - { - $source = $this->getTestDecoder(1); - $this->assertFalse($source->isSplFileInfo()); - - $img = Mockery::mock('SplFileInfo'); - $source = $this->getTestDecoder($img); - $this->assertTrue($source->isSplFileInfo()); - - $img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile', 'SplFileInfo'); - $this->assertTrue($source->isSplFileInfo()); - } - - public function testIsSymfonyUpload() - { - $source = $this->getTestDecoder(1); - $this->assertFalse($source->isSymfonyUpload()); - - $img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile'); - $source = $this->getTestDecoder($img); - $this->assertTrue($source->isSymfonyUpload()); - } - - public function testIsDataUrl() - { - $source = $this->getTestDecoder('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC'); - $this->assertTrue($source->isDataUrl()); - - $source = $this->getTestDecoder(null); - $this->assertFalse($source->isDataUrl()); - } - - public function testIsBase64() - { - $decoder = $this->getTestDecoder(null); - $this->assertFalse($decoder->isBase64()); - - $decoder = $this->getTestDecoder('random'); - $this->assertFalse($decoder->isBase64()); - - $base64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC"; - $decoder = $this->getTestDecoder($base64); - $this->assertTrue($decoder->isBase64()); - - $base64WithNewlines = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . - '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . - 'cRvs4UAAAAAElFTkSuQmCC'; - - $decoder = $this->getTestDecoder($base64WithNewlines); - $this->assertTrue($decoder->isBase64()); - } - - public function getTestDecoder($data) - { - return $this->getMockForAbstractClass('\Intervention\Image\AbstractDecoder', [$data]); - } -} diff --git a/tests/AbstractDriverTest.php b/tests/AbstractDriverTest.php deleted file mode 100644 index 704c0992..00000000 --- a/tests/AbstractDriverTest.php +++ /dev/null @@ -1,21 +0,0 @@ -getMockForAbstractClass('\Intervention\Image\AbstractDriver'); - $command = $driver->executeCommand($image, 'xxxxxxxxxxxxxxxxxxxxxxx', []); - } -} diff --git a/tests/AbstractFontTest.php b/tests/AbstractFontTest.php deleted file mode 100644 index 37dfe56d..00000000 --- a/tests/AbstractFontTest.php +++ /dev/null @@ -1,86 +0,0 @@ -getMockForAbstractClass('\Intervention\Image\AbstractFont', ['test']); - $this->assertEquals('test', $font->text); - } - - public function testText() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->text('test'); - $this->assertEquals('test', $font->text); - } - - public function testSize() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->size(16); - $this->assertEquals(16, $font->size); - } - - public function testColor() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->color('#ffffff'); - $this->assertEquals('#ffffff', $font->color); - } - - public function testAngle() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->angle(30); - $this->assertEquals(30, $font->angle); - } - - public function testAlign() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->align('right'); - $this->assertEquals('right', $font->align); - } - - public function testValign() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->valign('top'); - $this->assertEquals('top', $font->valign); - } - - public function testKerning() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->kerning(10.5); - $this->assertEquals(10.5, $font->kerning); - } - - public function testFile() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->file('test.ttf'); - $this->assertEquals('test.ttf', $font->file); - } - - public function testCountLines() - { - $font = $this->getMockForAbstractClass('\Intervention\Image\AbstractFont'); - $font->text('foo'.PHP_EOL.'bar'.PHP_EOL.'baz'); - $this->assertEquals(3, $font->countLines()); - $font->text("foo\nbar\nbaz"); - $this->assertEquals(3, $font->countLines()); - $font->text('foo - bar - baz'); - $this->assertEquals(3, $font->countLines()); - } -} diff --git a/tests/AbstractShapeTest.php b/tests/AbstractShapeTest.php deleted file mode 100644 index 64f88adc..00000000 --- a/tests/AbstractShapeTest.php +++ /dev/null @@ -1,43 +0,0 @@ -getMockForAbstractClass('\Intervention\Image\AbstractShape'); - $shape->background('foo'); - $this->assertEquals('foo', $shape->background); - $this->assertEquals(0, $shape->border_width); - } - - public function testBorder() - { - $shape = $this->getMockForAbstractClass('\Intervention\Image\AbstractShape'); - $shape->border(4); - $this->assertEquals(4, $shape->border_width); - $this->assertEquals('#000000', $shape->border_color); - } - - public function testBorderWithColor() - { - $shape = $this->getMockForAbstractClass('\Intervention\Image\AbstractShape'); - $shape->border(3, '#ff00ff'); - $this->assertEquals(3, $shape->border_width); - $this->assertEquals('#ff00ff', $shape->border_color); - } - - public function testHasBorder() - { - $shape = $this->getMockForAbstractClass('\Intervention\Image\AbstractShape'); - $this->assertFalse($shape->hasBorder()); - $shape->border(1); - $this->assertTrue($shape->hasBorder()); - } -} diff --git a/tests/ArgumentTest.php b/tests/ArgumentTest.php deleted file mode 100644 index a40a1080..00000000 --- a/tests/ArgumentTest.php +++ /dev/null @@ -1,422 +0,0 @@ -getMockedCommand(['foo'])); - $this->validateArgument($arg, 'foo'); - - $arg = new Argument($this->getMockedCommand(['foo', 'bar']), 1); - $this->validateArgument($arg, 'bar'); - - $arg = new Argument($this->getMockedCommand(), 0); - $this->validateArgument($arg, null); - } - - public function testRequiredPass() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->required(); - $this->validateArgument($arg, 'foo'); - - $arg = new Argument($this->getMockedCommand([null])); - $arg->required(); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([0])); - $arg->required(); - $this->validateArgument($arg, 0); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testRequiredFail() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->required(); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testRequiredFailSecondParameter() - { - $arg = new Argument($this->getMockedCommand(['foo']), 1); - $arg->required(); - } - - public function testTypeIntegerPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('integer'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([123])); - $arg->type('integer'); - $this->validateArgument($arg, 123); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeIntegerFail() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('integer'); - } - - public function testTypeArrayPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('array'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([[1,2,3]])); - $arg->type('array'); - $this->validateArgument($arg, [1,2,3]); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeArrayFail() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('array'); - } - - public function testTypeDigitPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('digit'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([0])); - $arg->type('digit'); - $this->validateArgument($arg, 0); - - $arg = new Argument($this->getMockedCommand([123])); - $arg->type('digit'); - $this->validateArgument($arg, 123); - - $arg = new Argument($this->getMockedCommand([5.0])); - $arg->type('digit'); - $this->validateArgument($arg, 5.0); - - $arg = new Argument($this->getMockedCommand([-10])); - $arg->type('digit'); - $this->validateArgument($arg, -10); - - $arg = new Argument($this->getMockedCommand([-10.0])); - $arg->type('digit'); - $this->validateArgument($arg, -10.0); - - $arg = new Argument($this->getMockedCommand(['12'])); - $arg->type('digit'); - $this->validateArgument($arg, '12'); - - $arg = new Argument($this->getMockedCommand(['12.0'])); - $arg->type('digit'); - $this->validateArgument($arg, '12.0'); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeDigitFailString() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('digit'); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeDigitFailFloat() - { - $arg = new Argument($this->getMockedCommand([12.5])); - $arg->type('digit'); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeDigitFailBool() - { - $arg = new Argument($this->getMockedCommand([true])); - $arg->type('digit'); - } - - public function testTypeNumericPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('numeric'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([12.3])); - $arg->type('numeric'); - $this->validateArgument($arg, 12.3); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeNumericFail() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('numeric'); - } - - public function testTypeBooleanPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('boolean'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([true])); - $arg->type('boolean'); - $this->validateArgument($arg, true); - - $arg = new Argument($this->getMockedCommand([false])); - $arg->type('boolean'); - $this->validateArgument($arg, false); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeBooleanFail() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('boolean'); - } - - public function testTypeStringPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('string'); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('string'); - $this->validateArgument($arg, 'foo'); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeStringFail() - { - $arg = new Argument($this->getMockedCommand([12])); - $arg->type('string'); - } - - public function testTypeClosurePass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->type('closure'); - $this->validateArgument($arg, null); - - $c = function ($foo) {}; - $arg = new Argument($this->getMockedCommand([$c])); - $arg->type('closure'); - $this->validateArgument($arg, $c); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testTypeClosureFail() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->type('closure'); - } - - public function testBetweenPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->between(0, 10); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([null])); - $arg->between(0, 10); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([4.5])); - $arg->between(0, 10); - $this->validateArgument($arg, 4.5); - - $arg = new Argument($this->getMockedCommand([4.5])); - $arg->between(10, 1); - $this->validateArgument($arg, 4.5); - - $arg = new Argument($this->getMockedCommand([0])); - $arg->between(0, 10); - $this->validateArgument($arg, 0); - - $arg = new Argument($this->getMockedCommand([10])); - $arg->between(0, 10); - $this->validateArgument($arg, 10); - - $arg = new Argument($this->getMockedCommand([0])); - $arg->between(-100, 100); - $this->validateArgument($arg, 0); - - $arg = new Argument($this->getMockedCommand([-100])); - $arg->between(-100, 100); - $this->validateArgument($arg, -100); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testBetweenFailString() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->between(1, 10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testBetweenFailAbove() - { - $arg = new Argument($this->getMockedCommand([10.9])); - $arg->between(0, 10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testBetweenFailBelow() - { - $arg = new Argument($this->getMockedCommand([-1])); - $arg->between(0, 10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testBetweenFail() - { - $arg = new Argument($this->getMockedCommand([-1000])); - $arg->between(-100, 100); - } - - public function testMinPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->min(10); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([null])); - $arg->min(10); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([50])); - $arg->min(10); - $this->validateArgument($arg, 50); - - $arg = new Argument($this->getMockedCommand([50])); - $arg->min(50); - $this->validateArgument($arg, 50); - - $arg = new Argument($this->getMockedCommand([50])); - $arg->min(-10); - $this->validateArgument($arg, 50); - - $arg = new Argument($this->getMockedCommand([-10])); - $arg->min(-10); - $this->validateArgument($arg, -10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testMinFailString() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->min(10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testMinFail() - { - $arg = new Argument($this->getMockedCommand([10.9])); - $arg->min(11); - } - - public function testMaxPass() - { - $arg = new Argument($this->getMockedCommand([])); - $arg->max(100); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([null])); - $arg->max(100); - $this->validateArgument($arg, null); - - $arg = new Argument($this->getMockedCommand([50])); - $arg->max(100); - $this->validateArgument($arg, 50); - - $arg = new Argument($this->getMockedCommand([100])); - $arg->max(100); - $this->validateArgument($arg, 100); - - $arg = new Argument($this->getMockedCommand([-100])); - $arg->max(-10); - $this->validateArgument($arg, -100); - - $arg = new Argument($this->getMockedCommand([-10])); - $arg->max(-10); - $this->validateArgument($arg, -10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testMaxFailString() - { - $arg = new Argument($this->getMockedCommand(['foo'])); - $arg->max(10); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testMaxFail() - { - $arg = new Argument($this->getMockedCommand([25])); - $arg->max(10); - } - - public function testValueDefault() - { - $arg = new Argument($this->getMockedCommand()); - $value = $arg->value('foo'); - $this->assertEquals('foo', $value); - - $arg = new Argument($this->getMockedCommand([null])); - $value = $arg->value('foo'); - $this->assertEquals('foo', $value); - } - - private function validateArgument($argument, $value) - { - $this->assertInstanceOf('\Intervention\Image\Commands\Argument', $argument); - $this->assertEquals($value, $argument->value()); - } - - private function getMockedCommand($arguments = []) - { - return $this->getMockForAbstractClass('\Intervention\Image\Commands\AbstractCommand', [$arguments]); - } -} diff --git a/tests/BackupCommandTest.php b/tests/BackupCommandTest.php deleted file mode 100644 index f7d6960f..00000000 --- a/tests/BackupCommandTest.php +++ /dev/null @@ -1,65 +0,0 @@ -shouldReceive('cloneCore')->once(); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image', [$driver]); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setBackup')->once(); - $command = new BackupGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdWithName() - { - $driver = Mockery::mock('Intervention\Image\Gd\Driver'); - $driver->shouldReceive('cloneCore')->once(); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image', [$driver]); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setBackup')->once(); - $command = new BackupGd(['name' => 'fooBackup']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickWithoutName() - { - $driver = Mockery::mock('Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('cloneCore')->once(); - $imagick = Mockery::mock('Imagick'); - $image = Mockery::mock('Intervention\Image\Image', [$driver]); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('setBackup')->once(); - $command = new BackupImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickWithName() - { - $driver = Mockery::mock('Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('cloneCore')->once(); - $imagick = Mockery::mock('Imagick'); - $image = Mockery::mock('Intervention\Image\Image', [$driver]); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('setBackup')->once(); - $command = new BackupImagick(['name' => 'fooBackup']); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/BlurCommandTest.php b/tests/BlurCommandTest.php deleted file mode 100644 index 6267d48e..00000000 --- a/tests/BlurCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->times(2)->andReturn($resource); - $command = new BlurGd([2]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('blurimage')->with(2, 1)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new BlurImagick([2]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/BrightnessCommandTest.php b/tests/BrightnessCommandTest.php deleted file mode 100644 index 2c225d0b..00000000 --- a/tests/BrightnessCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new BrightnessGd([12]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('modulateimage')->with(112, 100, 100)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new BrightnessImagick([12]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/ChecksumCommandTest.php b/tests/ChecksumCommandTest.php deleted file mode 100644 index 5be7ca68..00000000 --- a/tests/ChecksumCommandTest.php +++ /dev/null @@ -1,27 +0,0 @@ -shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('pickColor')->times(9)->andReturn($color); - $command = new ChecksumCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals('ec9cbdb71be04e26b4a89333f20c273b', $command->getOutput()); - } -} diff --git a/tests/CircleCommandTest.php b/tests/CircleCommandTest.php deleted file mode 100644 index 9c916a14..00000000 --- a/tests/CircleCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new CircleCommand([250, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('drawimage'); - $driver = Mockery::mock('\Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('getDriverName')->once()->andReturn('Imagick'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - - $command = new CircleCommand([25, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - -} diff --git a/tests/CircleShapeTest.php b/tests/CircleShapeTest.php deleted file mode 100644 index 18a51482..00000000 --- a/tests/CircleShapeTest.php +++ /dev/null @@ -1,52 +0,0 @@ -assertInstanceOf('Intervention\Image\Gd\Shapes\CircleShape', $circle); - $this->assertEquals(250, $circle->diameter); - - } - - public function testGdApplyToImage() - { - $core = imagecreatetruecolor(300, 200); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $circle = new CircleGd(250); - $result = $circle->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Gd\Shapes\CircleShape', $circle); - $this->assertTrue($result); - } - - public function testImagickConstructor() - { - $circle = new CircleImagick(250); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\CircleShape', $circle); - $this->assertEquals(250, $circle->width); - } - - public function testImagickApplyToImage() - { - $core = Mockery::mock('\Imagick'); - $core->shouldReceive('drawimage')->once(); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $circle = new CircleImagick(250); - $result = $circle->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\CircleShape', $circle); - $this->assertTrue($result); - } - -} diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php new file mode 100644 index 00000000..f02d1843 --- /dev/null +++ b/tests/CollectionTest.php @@ -0,0 +1,102 @@ +assertInstanceOf(Collection::class, $collection); + + $collection = Collection::create(['foo', 'bar', 'baz']); + $this->assertInstanceOf(Collection::class, $collection); + } + + public function testIterator() + { + $collection = new Collection(['foo', 'bar', 'baz']); + foreach ($collection as $key => $item) { + switch ($key) { + case 0: + $this->assertEquals('foo', $item); + break; + + case 1: + $this->assertEquals('bar', $item); + break; + + case 2: + $this->assertEquals('baz', $item); + break; + } + } + } + + public function testCount() + { + $collection = new Collection(['foo', 'bar', 'baz']); + $this->assertEquals(3, $collection->count()); + $this->assertEquals(3, count($collection)); + } + + public function testFirstLast() + { + $collection = new Collection(['foo', 'bar', 'baz']); + $this->assertEquals('foo', $collection->first()); + $this->assertEquals('baz', $collection->last()); + + $collection = new Collection(); + $this->assertNull($collection->first()); + $this->assertNull($collection->last()); + } + + public function testPush() + { + $collection = new Collection(['foo', 'bar', 'baz']); + $this->assertEquals(3, $collection->count()); + $result = $collection->push('test'); + $this->assertEquals(4, $collection->count()); + $this->assertInstanceOf(Collection::class, $result); + } + + public function testPushEach() + { + $collection = Collection::create()->pushEach(['foo', 'bar', 'baz'], function ($item) { + return strtoupper($item); + }); + $this->assertEquals(3, $collection->count()); + $this->assertEquals('FOO', $collection->get(0)); + $this->assertEquals('BAR', $collection->get(1)); + $this->assertEquals('BAZ', $collection->get(2)); + } + + public function testGet() + { + $collection = new Collection(['foo', 'bar', 'baz']); + $this->assertEquals('foo', $collection->get(0)); + $this->assertEquals('bar', $collection->get(1)); + $this->assertEquals('baz', $collection->get(2)); + $this->assertNull($collection->get(3)); + } + + public function testToArray() + { + $collection = new Collection(['foo', 'bar', 'baz']); + $this->assertEquals(['foo', 'bar', 'baz'], $collection->toArray()); + } + + public function testMap(): void + { + $collection = new Collection(['FOO', 'BAR', 'BAZ']); + $mapped = $collection->map(function ($item) { + return strtolower($item); + }); + $this->assertInstanceOf(Collection::class, $collection); + $this->assertInstanceOf(Collection::class, $mapped); + $this->assertEquals(['FOO', 'BAR', 'BAZ'], $collection->toArray()); + $this->assertEquals(['foo', 'bar', 'baz'], $mapped->toArray()); + } +} diff --git a/tests/ColorizeCommandTest.php b/tests/ColorizeCommandTest.php deleted file mode 100644 index 0b3f9ece..00000000 --- a/tests/ColorizeCommandTest.php +++ /dev/null @@ -1,37 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new ColorizeGd([20, 0, -40]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getquantumrange')->with()->once()->andReturn(['quantumRangeLong' => 42]); - $imagick->shouldReceive('levelimage')->with(0, 4, 42, \Imagick::CHANNEL_RED)->once()->andReturn(true); - $imagick->shouldReceive('levelimage')->with(0, 1, 42, \Imagick::CHANNEL_GREEN)->once()->andReturn(true); - $imagick->shouldReceive('levelimage')->with(0, 0.6, 42, \Imagick::CHANNEL_BLUE)->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->times(4)->andReturn($imagick); - $command = new ColorizeImagick([20, 0, -40]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/ConstraintTest.php b/tests/ConstraintTest.php deleted file mode 100644 index 0ac3375d..00000000 --- a/tests/ConstraintTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getMockedSize(800, 600); - $constraint = new Constraint($size); - $this->assertInstanceOf('Intervention\Image\Constraint', $constraint); - $this->assertFalse($constraint->isFixed(Constraint::ASPECTRATIO)); - $this->assertFalse($constraint->isFixed(Constraint::UPSIZE)); - } - - public function testSetOnlyAspectRatio() - { - $size = $this->getMockedSize(800, 600); - $constraint = new Constraint($size); - $constraint->aspectRatio(); - $this->assertTrue($constraint->isFixed(Constraint::ASPECTRATIO)); - $this->assertFalse($constraint->isFixed(Constraint::UPSIZE)); - } - - public function testSetOnlyUpsize() - { - $size = $this->getMockedSize(800, 600); - $constraint = new Constraint($size); - $constraint->upsize(); - $this->assertFalse($constraint->isFixed(Constraint::ASPECTRATIO)); - $this->assertTrue($constraint->isFixed(Constraint::UPSIZE)); - } - - public function testSetAspectratioAndUpsize() - { - $size = $this->getMockedSize(800, 600); - $constraint = new Constraint($size); - $constraint->aspectRatio(); - $constraint->upsize(); - $this->assertTrue($constraint->isFixed(Constraint::ASPECTRATIO)); - $this->assertTrue($constraint->isFixed(Constraint::UPSIZE)); - } - - private function getMockedSize($width, $height) - { - $size = Mockery::mock('\Intervention\Image\Size', [$width, $height]); - $size->shouldReceive('getWidth')->andReturn($width); - $size->shouldReceive('getHeight')->andReturn($height); - $size->shouldReceive('getRatio')->andReturn($width/$height); - return $size; - } -} diff --git a/tests/ContrastCommandTest.php b/tests/ContrastCommandTest.php deleted file mode 100644 index 9b81917a..00000000 --- a/tests/ContrastCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new ContrastGd([20]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('sigmoidalcontrastimage')->with(true, 5, 0)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new ContrastImagick([20]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/CropCommandTest.php b/tests/CropCommandTest.php deleted file mode 100644 index 23ac95ba..00000000 --- a/tests/CropCommandTest.php +++ /dev/null @@ -1,36 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new CropGd([100, 150, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('cropimage')->with(100, 150, 10, 20)->andReturn(true); - $imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->once(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->times(2)->andReturn($imagick); - $command = new CropImagick([100, 150, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/DestroyCommandTest.php b/tests/DestroyCommandTest.php deleted file mode 100644 index cc788463..00000000 --- a/tests/DestroyCommandTest.php +++ /dev/null @@ -1,46 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getBackups')->once()->andReturn($backups); - $command = new DestroyGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('clear')->with()->andReturn(true); - - $backup = Mockery::mock('Imagick'); - $backup->shouldReceive('clear')->with()->andReturn(true); - $backups = [$backup]; - - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('getBackups')->once()->andReturn($backups); - $command = new DestroyImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/DriverTest.php b/tests/DriverTest.php deleted file mode 100644 index 5cd8a36e..00000000 --- a/tests/DriverTest.php +++ /dev/null @@ -1,61 +0,0 @@ -newImage(300, 200, '00ff00'); - $this->assertInstanceOf('\Intervention\Image\Image', $image); - $this->assertInstanceOf('\Intervention\Image\Gd\Driver', $image->getDriver()); - $this->assertInternalType('resource', $image->getCore()); - } - - public function testNewImageImagick() - { - $driver = new ImagickDriver( - Mockery::mock('\Intervention\Image\Imagick\Decoder'), - Mockery::mock('\Intervention\Image\Imagick\Encoder') - ); - - $image = $driver->newImage(300, 200, '00ff00'); - $this->assertInstanceOf('\Intervention\Image\Image', $image); - $this->assertInstanceOf('\Intervention\Image\Imagick\Driver', $image->getDriver()); - $this->assertInstanceOf('\Imagick', $image->getCore()); - } - - public function testParseColorGd() - { - $driver = new GdDriver( - Mockery::mock('\Intervention\Image\Gd\Decoder'), - Mockery::mock('\Intervention\Image\Gd\Encoder') - ); - - $color = $driver->parseColor('00ff00'); - $this->assertInstanceOf('\Intervention\Image\Gd\Color', $color); - } - - public function testParseColorImagick() - { - $driver = new ImagickDriver( - Mockery::mock('\Intervention\Image\Imagick\Decoder'), - Mockery::mock('\Intervention\Image\Imagick\Encoder') - ); - - $color = $driver->parseColor('00ff00'); - $this->assertInstanceOf('\Intervention\Image\Imagick\Color', $color); - } -} diff --git a/tests/Drivers/Gd/ColorTest.php b/tests/Drivers/Gd/ColorTest.php new file mode 100644 index 00000000..848cadee --- /dev/null +++ b/tests/Drivers/Gd/ColorTest.php @@ -0,0 +1,75 @@ +assertInstanceOf(Color::class, $this->getTestColor()); + } + + public function testRed(): void + { + $color = $this->getTestColor(255, 0, 0); + $this->assertEquals(255, $color->red()); + } + + public function testGreen(): void + { + $color = $this->getTestColor(0, 150, 0); + $this->assertEquals(150, $color->green()); + } + + public function testBlue(): void + { + $color = $this->getTestColor(0, 0, 120); + $this->assertEquals(120, $color->blue()); + } + + public function testAlpha(): void + { + $color = $this->getTestColor(0, 0, 120, 0); + $this->assertEquals(1, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, 127); + $this->assertEquals(0, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, 64); + $this->assertEquals(.5, $color->alpha()); + } + + public function testToArray(): void + { + $color = $this->getTestColor(0, 0, 120, 0); + $this->assertEquals([0, 0, 120, 1], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, 127); + $this->assertEquals([0, 0, 120, 0], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, 64); + $this->assertEquals([0, 0, 120, .5], $color->toArray()); + } + + public function testToHex(): void + { + $color = $this->getTestColor(181, 55, 23); + $this->assertEquals('b53717', $color->toHex()); + $this->assertEquals('#b53717', $color->toHex('#')); + + $color = $this->getTestColor(181, 55, 23, 127); + $this->assertEquals('b53717', $color->toHex()); + $this->assertEquals('#b53717', $color->toHex('#')); + } +} diff --git a/tests/Drivers/Gd/Decoders/ArrayColorDecoderTest.php b/tests/Drivers/Gd/Decoders/ArrayColorDecoderTest.php new file mode 100644 index 00000000..585d864a --- /dev/null +++ b/tests/Drivers/Gd/Decoders/ArrayColorDecoderTest.php @@ -0,0 +1,21 @@ +decode([181, 55, 23, .5]); + $this->assertInstanceOf(Color::class, $color); + $this->assertEquals(181, $color->red()); + $this->assertEquals(55, $color->green()); + $this->assertEquals(23, $color->blue()); + $this->assertEquals(.5, $color->alpha()); + } +} diff --git a/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php b/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php new file mode 100644 index 00000000..3ccb4f4a --- /dev/null +++ b/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php @@ -0,0 +1,40 @@ +decode(file_get_contents(__DIR__ . '/../../../images/tile.png')); + $this->assertInstanceOf(Image::class, $image); + $this->assertEquals(16, $image->width()); + $this->assertEquals(16, $image->height()); + $this->assertCount(1, $image); + } + + public function testDecodeGif(): void + { + $decoder = new BinaryImageDecoder(); + $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/red.gif')); + $this->assertInstanceOf(Image::class, $image); + $this->assertEquals(16, $image->width()); + $this->assertEquals(16, $image->height()); + $this->assertCount(1, $image); + } + + public function testDecodeAnimatedGif(): void + { + $decoder = new BinaryImageDecoder(); + $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/cats.gif')); + $this->assertInstanceOf(Image::class, $image); + $this->assertEquals(75, $image->width()); + $this->assertEquals(50, $image->height()); + $this->assertCount(4, $image); + } +} diff --git a/tests/Drivers/Gd/Encoders/GifEncoderTest.php b/tests/Drivers/Gd/Encoders/GifEncoderTest.php new file mode 100644 index 00000000..e668ce22 --- /dev/null +++ b/tests/Drivers/Gd/Encoders/GifEncoderTest.php @@ -0,0 +1,40 @@ +setDelay(1); + $frame2 = new Frame($gd2); + $frame2->setDelay(.2); + $frame3 = new Frame($gd3); + $frame3->setDelay(1); + + return new Image(new Collection([$frame1, $frame2, $frame3])); + } + + public function testEncode(): void + { + $image = $this->getTestImage(); + $encoder = new GifEncoder(); + $result = $encoder->encode($image); + $this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageGif())); + } +} diff --git a/tests/Drivers/Gd/Encoders/JpegEncoderTest.php b/tests/Drivers/Gd/Encoders/JpegEncoderTest.php new file mode 100644 index 00000000..17af9db1 --- /dev/null +++ b/tests/Drivers/Gd/Encoders/JpegEncoderTest.php @@ -0,0 +1,29 @@ +getTestImage(); + $encoder = new JpegEncoder(); + $result = $encoder->encode($image); + $this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageJpeg)); + } +} \ No newline at end of file diff --git a/tests/Drivers/Gd/FrameTest.php b/tests/Drivers/Gd/FrameTest.php new file mode 100644 index 00000000..b17feb51 --- /dev/null +++ b/tests/Drivers/Gd/FrameTest.php @@ -0,0 +1,79 @@ +getTestFrame(); + $this->assertInstanceOf(Frame::class, $frame); + } + + public function testSetGetDelay() + { + $frame = $this->getTestFrame(); + $this->assertEquals(0, $frame->getDelay()); + + $result = $frame->setDelay(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getDelay()); + } + + public function testSetGetDispose() + { + $frame = $this->getTestFrame(); + $this->assertEquals(1, $frame->getDispose()); + + $result = $frame->setDispose(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getDispose()); + } + + public function testSetGetOffsetLeft() + { + $frame = $this->getTestFrame(); + $this->assertEquals(0, $frame->getOffsetLeft()); + + $result = $frame->setOffsetLeft(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetLeft()); + } + + public function testSetGetOffsetTop() + { + $frame = $this->getTestFrame(); + $this->assertEquals(0, $frame->getOffsetTop()); + + $result = $frame->setOffsetTop(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetTop()); + } + + public function testSetGetOffset() + { + $frame = $this->getTestFrame(); + $this->assertEquals(0, $frame->getOffsetTop()); + $this->assertEquals(0, $frame->getOffsetLeft()); + + $result = $frame->setOffset(100, 200); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetLeft()); + $this->assertEquals(200, $frame->getOffsetTop()); + } + + public function testToImage(): void + { + $frame = $this->getTestFrame(); + $this->assertInstanceOf(Image::class, $frame->toImage()); + } +} diff --git a/tests/Drivers/Gd/ImageFactoryTest.php b/tests/Drivers/Gd/ImageFactoryTest.php new file mode 100644 index 00000000..20bc9abd --- /dev/null +++ b/tests/Drivers/Gd/ImageFactoryTest.php @@ -0,0 +1,17 @@ +newImage(3, 2); + $this->assertInstanceOf(Image::class, $image); + } +} diff --git a/tests/Drivers/Gd/ImageTest.php b/tests/Drivers/Gd/ImageTest.php new file mode 100644 index 00000000..db5ddb78 --- /dev/null +++ b/tests/Drivers/Gd/ImageTest.php @@ -0,0 +1,46 @@ +image = new Image(new Collection([new Frame(imagecreatetruecolor(3, 2))])); + } + + public function testConstructor(): void + { + $this->assertInstanceOf(Image::class, $this->image); + } + + public function testIterator(): void + { + foreach ($this->image as $frame) { + $this->assertInstanceOf(Frame::class, $frame); + } + } + + public function testWidth(): void + { + $this->assertEquals(3, $this->image->width()); + } + + public function testHeight(): void + { + $this->assertEquals(2, $this->image->height()); + } + + public function testSize(): void + { + $this->assertInstanceOf(Size::class, $this->image->size()); + } +} diff --git a/tests/Drivers/Gd/InputHandlerTest.php b/tests/Drivers/Gd/InputHandlerTest.php new file mode 100644 index 00000000..f4d2d258 --- /dev/null +++ b/tests/Drivers/Gd/InputHandlerTest.php @@ -0,0 +1,62 @@ +expectException(DecoderException::class); + $result = $handler->handle(''); + } + + public function testHandleBinaryImage(): void + { + $handler = new InputHandler(); + $input = file_get_contents(__DIR__ . '/../../images/animation.gif'); + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleFilePathImage(): void + { + $handler = new InputHandler(); + $input = __DIR__ . '/../../images/animation.gif'; + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleBase64Image(): void + { + $handler = new InputHandler(); + $input = base64_encode(file_get_contents(__DIR__ . '/../../images/animation.gif')); + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleDataUriImage(): void + { + $handler = new InputHandler(); + $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleArrayColor(): void + { + $handler = new InputHandler(); + $input = [181, 55, 23, .5]; + $result = $handler->handle($input); + $this->assertInstanceOf(Color::class, $result); + } +} diff --git a/tests/Drivers/Imagick/ColorTest.php b/tests/Drivers/Imagick/ColorTest.php new file mode 100644 index 00000000..2768c7f6 --- /dev/null +++ b/tests/Drivers/Imagick/ColorTest.php @@ -0,0 +1,87 @@ +assertInstanceOf(Color::class, $this->getTestColor()); + } + + public function testRed(): void + { + $color = $this->getTestColor(255, 0, 0); + $this->assertEquals(255, $color->red()); + } + + public function testGreen(): void + { + $color = $this->getTestColor(0, 150, 0); + $this->assertEquals(150, $color->green()); + } + + public function testBlue(): void + { + $color = $this->getTestColor(0, 0, 120); + $this->assertEquals(120, $color->blue()); + } + + public function testAlpha(): void + { + $color = $this->getTestColor(0, 0, 120, 1); + $this->assertEquals(1, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, 0); + $this->assertEquals(0, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, .5); + $this->assertEquals(.5, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, .57); + $this->assertEquals(.57, $color->alpha()); + + $color = $this->getTestColor(0, 0, 120, .578); + $this->assertEquals(.58, $color->alpha()); + } + + public function testToArray(): void + { + $color = $this->getTestColor(0, 0, 120, 1); + $this->assertEquals([0, 0, 120, 1], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, 0); + $this->assertEquals([0, 0, 120, 0], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, .5); + $this->assertEquals([0, 0, 120, .5], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, .57); + $this->assertEquals([0, 0, 120, .57], $color->toArray()); + + $color = $this->getTestColor(0, 0, 120, .578); + $this->assertEquals([0, 0, 120, .58], $color->toArray()); + } + + public function testToHex(): void + { + $color = $this->getTestColor(181, 55, 23); + $this->assertEquals('b53717', $color->toHex()); + $this->assertEquals('#b53717', $color->toHex('#')); + + $color = $this->getTestColor(181, 55, 23, 127); + $this->assertEquals('b53717', $color->toHex()); + $this->assertEquals('#b53717', $color->toHex('#')); + } +} diff --git a/tests/Drivers/Imagick/Decoders/ArrayColorDecoderTest.php b/tests/Drivers/Imagick/Decoders/ArrayColorDecoderTest.php new file mode 100644 index 00000000..e0e16800 --- /dev/null +++ b/tests/Drivers/Imagick/Decoders/ArrayColorDecoderTest.php @@ -0,0 +1,21 @@ +decode([181, 55, 23, .5]); + $this->assertInstanceOf(Color::class, $color); + $this->assertEquals(181, $color->red()); + $this->assertEquals(55, $color->green()); + $this->assertEquals(23, $color->blue()); + $this->assertEquals(.5, $color->alpha()); + } +} diff --git a/tests/Drivers/Imagick/Encoders/GifEncoderTest.php b/tests/Drivers/Imagick/Encoders/GifEncoderTest.php new file mode 100644 index 00000000..9e51820e --- /dev/null +++ b/tests/Drivers/Imagick/Encoders/GifEncoderTest.php @@ -0,0 +1,42 @@ +newImage(30, 20, new ImagickPixel('red'), 'png'); + $frame1 = new Frame($imagick1); + $frame1->setDelay(50); + $imagick2 = new Imagick(); + $imagick2->newImage(30, 20, new ImagickPixel('green'), 'png'); + $frame2 = new Frame($imagick2); + $frame2->setDelay(50); + $imagick3 = new Imagick(); + $imagick3->newImage(30, 20, new ImagickPixel('blue'), 'png'); + $frame3 = new Frame($imagick3); + $frame3->setDelay(50); + + return new Image(new Collection([$frame1, $frame2, $frame3])); + } + + public function testEncode(): void + { + $image = $this->getTestImage(); + $encoder = new GifEncoder(); + $result = $encoder->encode($image); + $this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageGif())); + } +} diff --git a/tests/Drivers/Imagick/Encoders/JpegEncoderTest.php b/tests/Drivers/Imagick/Encoders/JpegEncoderTest.php new file mode 100644 index 00000000..7a01f54a --- /dev/null +++ b/tests/Drivers/Imagick/Encoders/JpegEncoderTest.php @@ -0,0 +1,33 @@ +newImage(3, 2, new ImagickPixel('red'), 'png'); + $frame = new Frame($imagick); + + return new Image(new Collection([$frame])); + } + + public function testEncode(): void + { + $image = $this->getTestImage(); + $encoder = new JpegEncoder(); + $result = $encoder->encode($image); + $this->assertTrue(MimeSniffer::createFromString($result)->matches(new ImageJpeg)); + } +} \ No newline at end of file diff --git a/tests/Drivers/Imagick/FrameTest.php b/tests/Drivers/Imagick/FrameTest.php new file mode 100644 index 00000000..c7c2a26d --- /dev/null +++ b/tests/Drivers/Imagick/FrameTest.php @@ -0,0 +1,87 @@ +newImage(3, 2, new ImagickPixel('red'), 'png'); + $imagick->setImageDelay(4); + $imagick->setImageDispose(5); + $imagick->setImagePage(3, 2, 8, 9); + + return new Frame($imagick); + } + + public function testConstructor(): void + { + $frame = $this->getTestFrame(); + $this->assertInstanceOf(Frame::class, $frame); + } + + public function testSetGetDelay() + { + $frame = $this->getTestFrame(); + $this->assertEquals(4, $frame->getDelay()); + + $result = $frame->setDelay(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getDelay()); + } + + public function testSetGetDispose() + { + $frame = $this->getTestFrame(); + $this->assertEquals(5, $frame->getDispose()); + + $result = $frame->setDispose(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getDispose()); + } + + public function testSetGetOffsetLeft() + { + $frame = $this->getTestFrame(); + $this->assertEquals(8, $frame->getOffsetLeft()); + + $result = $frame->setOffsetLeft(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetLeft()); + } + + public function testSetGetOffsetTop() + { + $frame = $this->getTestFrame(); + $this->assertEquals(9, $frame->getOffsetTop()); + + $result = $frame->setOffsetTop(100); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetTop()); + } + + public function testSetGetOffset() + { + $frame = $this->getTestFrame(); + $this->assertEquals(8, $frame->getOffsetLeft()); + $this->assertEquals(9, $frame->getOffsetTop()); + + $result = $frame->setOffset(100, 200); + $this->assertInstanceOf(Frame::class, $result); + $this->assertEquals(100, $frame->getOffsetLeft()); + $this->assertEquals(200, $frame->getOffsetTop()); + } + + public function testToImage(): void + { + $frame = $this->getTestFrame(); + $this->assertInstanceOf(Image::class, $frame->toImage()); + } +} diff --git a/tests/Drivers/Imagick/ImageTest.php b/tests/Drivers/Imagick/ImageTest.php new file mode 100644 index 00000000..611825d0 --- /dev/null +++ b/tests/Drivers/Imagick/ImageTest.php @@ -0,0 +1,51 @@ +newImage(3, 2, new ImagickPixel('red'), 'png'); + + $this->image = new Image(new Collection([new Frame($imagick)])); + } + + public function testConstructor(): void + { + $this->assertInstanceOf(Image::class, $this->image); + } + + public function testIterator(): void + { + foreach ($this->image as $frame) { + $this->assertInstanceOf(Frame::class, $frame); + } + } + + public function testWidth(): void + { + $this->assertEquals(3, $this->image->width()); + } + + public function testHeight(): void + { + $this->assertEquals(2, $this->image->height()); + } + + public function testSize(): void + { + $this->assertInstanceOf(Size::class, $this->image->size()); + } +} diff --git a/tests/Drivers/Imagick/InputHandlerTest.php b/tests/Drivers/Imagick/InputHandlerTest.php new file mode 100644 index 00000000..6bc689ba --- /dev/null +++ b/tests/Drivers/Imagick/InputHandlerTest.php @@ -0,0 +1,62 @@ +expectException(DecoderException::class); + $result = $handler->handle(''); + } + + public function testHandleBinaryImage(): void + { + $handler = new InputHandler(); + $input = file_get_contents(__DIR__ . '/../../images/animation.gif'); + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleFilePathImage(): void + { + $handler = new InputHandler(); + $input = __DIR__ . '/../../images/animation.gif'; + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleBase64Image(): void + { + $handler = new InputHandler(); + $input = base64_encode(file_get_contents(__DIR__ . '/../../images/animation.gif')); + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleDataUriImage(): void + { + $handler = new InputHandler(); + $input = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; + $result = $handler->handle($input); + $this->assertInstanceOf(Image::class, $result); + } + + public function testHandleArrayColor(): void + { + $handler = new InputHandler(); + $input = [181, 55, 23, .5]; + $result = $handler->handle($input); + $this->assertInstanceOf(Color::class, $result); + } +} diff --git a/tests/EllipseCommandTest.php b/tests/EllipseCommandTest.php deleted file mode 100644 index d3b8b2b3..00000000 --- a/tests/EllipseCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new EllipseCommand([250, 150, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('drawimage'); - $driver = Mockery::mock('\Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('getDriverName')->once()->andReturn('Imagick'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - - $command = new EllipseCommand([250, 150, 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - -} diff --git a/tests/EllipseShapeTest.php b/tests/EllipseShapeTest.php deleted file mode 100644 index 9c857275..00000000 --- a/tests/EllipseShapeTest.php +++ /dev/null @@ -1,55 +0,0 @@ -assertInstanceOf('Intervention\Image\Gd\Shapes\EllipseShape', $ellipse); - $this->assertEquals(250, $ellipse->width); - $this->assertEquals(150, $ellipse->height); - - } - - public function testGdApplyToImage() - { - $core = imagecreatetruecolor(300, 200); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $ellipse = new EllipseGd(250, 150); - $result = $ellipse->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Gd\Shapes\EllipseShape', $ellipse); - $this->assertTrue($result); - } - - public function testImagickConstructor() - { - $ellipse = new EllipseImagick(250, 150); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\EllipseShape', $ellipse); - $this->assertEquals(250, $ellipse->width); - $this->assertEquals(150, $ellipse->height); - - } - - public function testImagickApplyToImage() - { - $core = Mockery::mock('\Imagick'); - $core->shouldReceive('drawimage')->once(); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $ellipse = new EllipseImagick(250, 150); - $result = $ellipse->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\EllipseShape', $ellipse); - $this->assertTrue($result); - } - -} diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php deleted file mode 100644 index f68818df..00000000 --- a/tests/EncoderTest.php +++ /dev/null @@ -1,339 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'jpg', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/jpeg; charset=binary', $this->getMime($encoder->result)); - } - - public function testProcessPngGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'png', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/png; charset=binary', $this->getMime($encoder->result)); - } - - public function testProcessGifGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'gif', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/gif; charset=binary', $this->getMime($encoder->result)); - } - - public function testProcessWebpGd() - { - if (function_exists('imagewebp')) { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'webp', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/webp; charset=binary', $this->getMime($encoder->result)); - } - } - - public function testProcessWebpGdWithUnSupportedPalette() - { - if (function_exists('imagewebp')) { - $core = imagecreatefrompng(__DIR__.'/images/black-friday.png'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'webp', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/webp; charset=binary', $this->getMime($encoder->result)); - } - } - - public function testProcessAvifGd() - { - if (function_exists('imageavif')) { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'avif', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/avif; charset=binary', $this->getMime($encoder->result)); - } - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessHeicGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'heic', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessTiffGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'tif', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testProcessBmpGd() - { - if (function_exists('imagebmp')) { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'bmp', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/x-ms-bmp; charset=binary', $this->getMime($encoder->result)); - } - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessIcoGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'ico', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessPsdGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'psd', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testProcessUnknownWithMimeGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->mime = 'image/jpeg'; - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/jpeg; charset=binary', $this->getMime($encoder->result)); - } - - public function testProcessUnknownGd() - { - $core = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $encoder = new GdEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('image/jpeg; charset=binary', $this->getMime($encoder->result)); - } - - public function testProcessJpegImagick() - { - $core = $this->getImagickMock('jpeg'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'jpg', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-jpeg', $encoder->result); - } - - public function testProcessPngImagick() - { - $core = $this->getImagickMock('png'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'png', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-png', $encoder->result); - } - - public function testProcessGifImagick() - { - $core = $this->getImagickMock('gif'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'gif', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-gif', $encoder->result); - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessWebpImagick() - { - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'webp', 90); - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessAvifImagick() - { - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'avif', 90); - } - - /** - * @expectedException \Intervention\Image\Exception\NotSupportedException - */ - public function testProcessHeicImagick() - { - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $img = $encoder->process($image, 'heic', 90); - } - - public function testProcessTiffImagick() - { - $core = $this->getImagickMock('tiff'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'tiff', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-tiff', $encoder->result); - } - - public function testProcessBmpImagick() - { - $core = $this->getImagickMock('bmp'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'bmp', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-bmp', $encoder->result); - } - - public function testProcessIcoImagick() - { - $core = $this->getImagickMock('ico'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'ico', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-ico', $encoder->result); - } - - public function testProcessPsdImagick() - { - $core = $this->getImagickMock('psd'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, 'psd', 90); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-psd', $encoder->result); - } - - public function testProcessUnknownWithMimeImagick() - { - $core = $this->getImagickMock('jpeg'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->mime = 'image/jpeg'; - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-jpeg', $encoder->result); - } - - public function testProcessUnknownImagick() - { - $core = $this->getImagickMock('jpeg'); - $encoder = new ImagickEncoder; - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $image->shouldReceive('setEncoded')->once()->andReturn($image); - $img = $encoder->process($image, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('mock-jpeg', $encoder->result); - } - - public function getImagickMock($type) - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('setformat')->with($type)->once(); - $imagick->shouldReceive('setimageformat')->once(); - $imagick->shouldReceive('setcompression')->once(); - $imagick->shouldReceive('setimagecompression')->once(); - $imagick->shouldReceive('setcompressionquality'); - $imagick->shouldReceive('setimagecompressionquality'); - $imagick->shouldReceive('setimagebackgroundcolor'); - $imagick->shouldReceive('setbackgroundcolor'); - $imagick->shouldReceive('mergeimagelayers')->andReturn($imagick); - $imagick->shouldReceive('getimagesblob')->once()->andReturn(sprintf('mock-%s', $type)); - return $imagick; - } - - public function getMime($data) - { - $finfo = new finfo(FILEINFO_MIME); - return $finfo->buffer($data); - } -} diff --git a/tests/ExifCommandTest.php b/tests/ExifCommandTest.php deleted file mode 100644 index 8b051c95..00000000 --- a/tests/ExifCommandTest.php +++ /dev/null @@ -1,112 +0,0 @@ -dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new ExifCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - } - - public function testFetchDefined() - { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new ExifCommand(['Artist']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals('Oliver Vogel', $command->getOutput()); - } - - public function testFetchNonExisting() - { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new ExifCommand(['xxx']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } - - public function testFetchFromPng() - { - $image = new Image; - $image->dirname = __DIR__.'/images'; - $image->basename = 'star.png'; - $command = new ExifCommand(['Orientation']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } - - public function testImagickFetchAll() - { - $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); - $command = new \Intervention\Image\Imagick\Commands\ExifCommand([]); - $command->dontPreferExtension(); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - $this->assertEquals('Oliver Vogel', $command->getOutput()['Artist']); - } - - public function testImagickFetchDefined() - { - $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); - $command = new \Intervention\Image\Imagick\Commands\ExifCommand(['Artist']); - $command->dontPreferExtension(); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals('Oliver Vogel', $command->getOutput()); - } - - public function testImagickNonExisting() - { - $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); - $command = new \Intervention\Image\Imagick\Commands\ExifCommand(['xx']); - $command->dontPreferExtension(); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } - - public function testImagickFallbackToExifExtenstion() - { - $image = $this->imagick()->make(__DIR__.'/images/exif.jpg'); - $command = new \Intervention\Image\Imagick\Commands\ExifCommand(['Artist']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals('Oliver Vogel', $command->getOutput()); - } - - private function imagick() - { - return new \Intervention\Image\ImageManager([ - 'driver' => 'imagick' - ]); - } -} diff --git a/tests/FileTest.php b/tests/FileTest.php deleted file mode 100644 index e1c01fd2..00000000 --- a/tests/FileTest.php +++ /dev/null @@ -1,28 +0,0 @@ -setFileInfoFromPath('tests/images/test.jpg'); - $this->assertEquals('tests/images', $file->dirname); - $this->assertEquals('test.jpg', $file->basename); - $this->assertEquals('jpg', $file->extension); - $this->assertEquals('test', $file->filename); - $this->assertEquals('image/jpeg', $file->mime); - } - - public function testBasePath() - { - $file = new File; - $this->assertNull(null, $file->basePath() ?: ''); - - $file->dirname = 'foo'; - $file->basename = 'bar'; - $this->assertEquals('foo/bar', $file->basePath()); - } -} diff --git a/tests/FillCommandTest.php b/tests/FillCommandTest.php deleted file mode 100644 index cbd3f1ed..00000000 --- a/tests/FillCommandTest.php +++ /dev/null @@ -1,93 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $command = new FillGd(['666666']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdFillArray() - { - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $command = new FillGd([[50, 50, 50]]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdFillArrayWithAlpha() - { - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $command = new FillGd([[50, 50, 50, .50]]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdFillWithCoordinates() - { - $driver = Mockery::mock('\Intervention\Image\Gd\Driver'); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->times(2)->andReturn($resource); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('setCore')->once(); - $driver->shouldReceive('newImage')->with(800, 600)->once()->andReturn($image); - $command = new FillGd(['#666666', 0, 0]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickFill() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('drawimage')->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getCore')->andReturn($imagick); - $command = new FillImagick(['666666']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickFillWithCoordinates() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getimagepixelcolor')->once()->andReturn('#000000'); - $imagick->shouldReceive('transparentpaintimage')->once()->andReturn(true); - $imagick->shouldReceive('compositeimage')->times(3)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->andReturn($imagick); - $image->shouldReceive('getWidth')->andReturn(800); - $image->shouldReceive('getHeight')->andReturn(600); - $command = new FillImagick(['666666', 0, 0]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/FitCommandTest.php b/tests/FitCommandTest.php deleted file mode 100644 index 23b1cb3b..00000000 --- a/tests/FitCommandTest.php +++ /dev/null @@ -1,93 +0,0 @@ -shouldReceive('getWidth')->times(2)->andReturn(800); - $cropped_size->shouldReceive('getHeight')->times(2)->andReturn(400); - $cropped_size->shouldReceive('resize')->with(200, 100, null)->once()->andReturn($cropped_size); - $cropped_size->pivot = Mockery::mock('\Intervention\Image\Point', [0, 100]); - $original_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $original_size->shouldReceive('fit')->with(Mockery::any(), 'center')->once()->andReturn($cropped_size); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($original_size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new FitGd([200, 100]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdFitWithPosition() - { - $cropped_size = Mockery::mock('\Intervention\Image\Size', [800, 400]); - $cropped_size->shouldReceive('getWidth')->times(2)->andReturn(800); - $cropped_size->shouldReceive('getHeight')->times(2)->andReturn(400); - $cropped_size->shouldReceive('resize')->with(200, 100, null)->once()->andReturn($cropped_size); - $cropped_size->pivot = Mockery::mock('\Intervention\Image\Point', [0, 100]); - $original_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $original_size->shouldReceive('fit')->with(Mockery::any(), 'top-left')->once()->andReturn($cropped_size); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($original_size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new FitGd([200, 100, null, 'top-left']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickFit() - { - $cropped_size = Mockery::mock('\Intervention\Image\Size', [800, 400]); - $cropped_size->shouldReceive('getWidth')->once()->andReturn(200); - $cropped_size->shouldReceive('getHeight')->once()->andReturn(100); - $cropped_size->shouldReceive('resize')->with(200, 100, null)->once()->andReturn($cropped_size); - $cropped_size->pivot = Mockery::mock('\Intervention\Image\Point', [0, 100]); - $original_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $original_size->shouldReceive('fit')->with(Mockery::any(), 'center')->once()->andReturn($cropped_size); - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('cropimage')->with(800, 400, 0, 100)->andReturn(true); - $imagick->shouldReceive('scaleimage')->with(200, 100)->once()->andReturn(true); - $imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($original_size); - $image->shouldReceive('getCore')->times(3)->andReturn($imagick); - $command = new FitImagick([200, 100]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickFitWithPosition() - { - $cropped_size = Mockery::mock('\Intervention\Image\Size', [800, 400]); - $cropped_size->shouldReceive('getWidth')->once()->andReturn(200); - $cropped_size->shouldReceive('getHeight')->once()->andReturn(100); - $cropped_size->shouldReceive('resize')->with(200, 100, null)->once()->andReturn($cropped_size); - $cropped_size->pivot = Mockery::mock('\Intervention\Image\Point', [0, 100]); - $original_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $original_size->shouldReceive('fit')->with(Mockery::any(), 'top-left')->once()->andReturn($cropped_size); - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('cropimage')->with(800, 400, 0, 100)->andReturn(true); - $imagick->shouldReceive('scaleimage')->with(200, 100)->once()->andReturn(true); - $imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($original_size); - $image->shouldReceive('getCore')->times(3)->andReturn($imagick); - $command = new FitImagick([200, 100, null, 'top-left']); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/FlipCommandTest.php b/tests/FlipCommandTest.php deleted file mode 100644 index 09370eb6..00000000 --- a/tests/FlipCommandTest.php +++ /dev/null @@ -1,45 +0,0 @@ -shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new FlipGd(['h']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('flopimage')->with()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new FlipImagick(['h']); - $result = $command->execute($image); - $this->assertTrue($result); - - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('flipimage')->with()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new FlipImagick(['v']); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/GammaCommandTest.php b/tests/GammaCommandTest.php deleted file mode 100644 index 6430236d..00000000 --- a/tests/GammaCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new GammaGd([1.4]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('gammaimage')->with(1.4)->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new GammaImagick([1.4]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/GdColorTest.php b/tests/GdColorTest.php deleted file mode 100644 index 7fa9f65f..00000000 --- a/tests/GdColorTest.php +++ /dev/null @@ -1,296 +0,0 @@ -validateColor($c, 255, 255, 255, 127); - } - - public function testParseNull() - { - $c = new Color; - $c->parse(null); - $this->validateColor($c, 255, 255, 255, 127); - } - - public function testParseInteger() - { - $c = new Color; - $c->parse(850736919); - $this->validateColor($c, 181, 55, 23, 50); - } - - public function testParseArray() - { - $c = new Color; - $c->parse([181, 55, 23, 0.5]); - $this->validateColor($c, 181, 55, 23, 64); - } - - public function testParseHexString() - { - $c = new Color; - $c->parse('#b53717'); - $this->validateColor($c, 181, 55, 23, 0); - } - - public function testParseRgbaString() - { - $c = new Color; - $c->parse('rgba(181, 55, 23, 1)'); - $this->validateColor($c, 181, 55, 23, 0); - } - - public function testInitFromInteger() - { - $c = new Color; - $c->initFromInteger(0); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromInteger(2147483647); - $this->validateColor($c, 255, 255, 255, 127); - $c->initFromInteger(16777215); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromInteger(2130706432); - $this->validateColor($c, 0, 0, 0, 127); - $c->initFromInteger(850736919); - $this->validateColor($c, 181, 55, 23, 50); - } - - public function testInitFromArray() - { - $c = new Color; - $c->initFromArray([0, 0, 0, 0]); - $this->validateColor($c, 0, 0, 0, 127); - $c->initFromArray([0, 0, 0, 1]); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromArray([255, 255, 255, 1]); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromArray([255, 255, 255, 0]); - $this->validateColor($c, 255, 255, 255, 127); - $c->initFromArray([255, 255, 255, 0.5]); - $this->validateColor($c, 255, 255, 255, 64); - $c->initFromArray([0, 0, 0]); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromArray([255, 255, 255]); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromArray([181, 55, 23]); - $this->validateColor($c, 181, 55, 23, 0); - $c->initFromArray([181, 55, 23, 0.5]); - $this->validateColor($c, 181, 55, 23, 64); - } - - public function testInitFromHexString() - { - $c = new Color; - $c->initFromString('#cccccc'); - $this->validateColor($c, 204, 204, 204, 0); - $c->initFromString('#b53717'); - $this->validateColor($c, 181, 55, 23, 0); - $c->initFromString('ffffff'); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromString('ff00ff'); - $this->validateColor($c, 255, 0, 255, 0); - $c->initFromString('#000'); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromString('000'); - $this->validateColor($c, 0, 0, 0, 0); - } - - public function testInitFromRgbString() - { - $c = new Color; - $c->initFromString('rgb(1, 14, 144)'); - $this->validateColor($c, 1, 14, 144, 0); - $c->initFromString('rgb (255, 255, 255)'); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromString('rgb(0,0,0)'); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromString('rgba(0,0,0,0)'); - $this->validateColor($c, 0, 0, 0, 127); - $c->initFromString('rgba(0,0,0,0.5)'); - $this->validateColor($c, 0, 0, 0, 64); - $c->initFromString('rgba(255, 0, 0, 0.5)'); - $this->validateColor($c, 255, 0, 0, 64); - $c->initFromString('rgba(204, 204, 204, 0.9)'); - $this->validateColor($c, 204, 204, 204, 13); - } - - public function testInitFromRgb() - { - $c = new Color; - $c->initFromRgb(0, 0, 0); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromRgb(255, 255, 255); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromRgb(181, 55, 23); - $this->validateColor($c, 181, 55, 23, 0); - } - - public function testInitFromRgba() - { - $c = new Color; - $c->initFromRgba(0, 0, 0, 1); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromRgba(255, 255, 255, 1); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromRgba(181, 55, 23, 1); - $this->validateColor($c, 181, 55, 23, 0); - $c->initFromRgba(181, 55, 23, 0); - $this->validateColor($c, 181, 55, 23, 127); - $c->initFromRgba(181, 55, 23, 0.5); - $this->validateColor($c, 181, 55, 23, 64); - } - - public function testGetInt() - { - $c = new Color; - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals(2147483647, $i); - - $c = new Color([255, 255, 255]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 16777215); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 16777215); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 1085617943); - - $c = new Color([181, 55, 23, 1]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 11876119); - - $c = new Color([0, 0, 0, 0]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 2130706432); - } - - public function testGetHex() - { - $c = new Color; - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'ffffff'); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'ffffff'); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'b53717'); - - $c = new Color([0, 0, 0, 0]); - $i = $c->getHex('#'); - $this->assertInternalType('string', $i); - $this->assertEquals($i, '#000000'); - } - - public function testGetArray() - { - $c = new Color; - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [255, 255, 255, 0]); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [255, 255, 255, 1]); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [181, 55, 23, 0.5]); - - $c = new Color([0, 0, 0, 1]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [0, 0, 0, 1]); - } - - public function testGetRgba() - { - $c = new Color; - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(255, 255, 255, 0.00)'); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(255, 255, 255, 1.00)'); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(181, 55, 23, 0.50)'); - - $c = new Color([0, 0, 0, 1]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(0, 0, 0, 1.00)'); - } - - public function testDiffers() - { - $c1 = new Color([0, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2)); - - $c1 = new Color([1, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(true, $c1->differs($c2)); - - $c1 = new Color([1, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2, 10)); - - $c1 = new Color([127, 127, 127]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(true, $c1->differs($c2, 49)); - - $c1 = new Color([127, 127, 127]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2, 50)); - } - - /** - * @expectedException \Intervention\Image\Exception\NotReadableException - */ - public function testParseUnknown() - { - $c = new Color('xxxxxxxxxxxxxxxxxxxx'); - } - - private function validateColor($obj, $r, $g, $b, $a) - { - $this->assertInstanceOf('Intervention\Image\Gd\Color', $obj); - $this->assertInternalType('int', $r); - $this->assertInternalType('int', $g); - $this->assertInternalType('int', $b); - $this->assertInternalType('int', $a); - $this->assertEquals($obj->r, $r); - $this->assertEquals($obj->g, $g); - $this->assertEquals($obj->b, $b); - $this->assertEquals($obj->a, $a); - } -} diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php deleted file mode 100644 index 7d7d5ecd..00000000 --- a/tests/GdSystemTest.php +++ /dev/null @@ -1,1703 +0,0 @@ -manager()->make('tests/images/circle.png'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - $this->assertEquals('tests/images', $img->dirname); - $this->assertEquals('circle.png', $img->basename); - $this->assertEquals('png', $img->extension); - $this->assertEquals('circle', $img->filename); - $this->assertEquals('image/png', $img->mime); - } - - /** - * @expectedException \Intervention\Image\Exception\NotReadableException - */ - public function testMakeFromPathBroken() - { - $this->manager()->make('tests/images/broken.png'); - } - - /** - * @expectedException \Intervention\Image\Exception\NotReadableException - */ - public function testMakeFromNotExisting() - { - $this->manager()->make('tests/images/not_existing.png'); - } - - public function testMakeFromString() - { - $str = file_get_contents('tests/images/circle.png'); - $img = $this->manager()->make($str); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - } - - public function testMakeFromResource() - { - $resource = imagecreatefrompng('tests/images/circle.png'); - $img = $this->manager()->make($resource); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - } - - public function testMakeFromDataUrl() - { - $img = $this->manager()->make('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - } - - public function testMakeFromBase64() - { - $img = $this->manager()->make('iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - } - - public function testMakeFromBase64WithNewlines() - { - $data = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . - '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . - 'cRvs4UAAAAAElFTkSuQmCC'; - - $img = $this->manager()->make($data); - - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - } - - public function testMakeFromWebp() - { - if (function_exists('imagecreatefromwebp')) { - $img = $this->manager()->make('tests/images/test.webp'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertEquals('image/webp', $img->mime); - $this->assertEquals('tests/images', $img->dirname); - $this->assertEquals('test.webp', $img->basename); - $this->assertEquals('webp', $img->extension); - $this->assertEquals('test', $img->filename); - } - } - - public function testCanvas() - { - $img = $this->manager()->canvas(30, 20); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(30, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testCanvasWithSolidBackground() - { - $img = $this->manager()->canvas(30, 20, 'b53717'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(30, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertEquals('#b53717', $img->pickColor(15, 15, 'hex')); - } - - public function testGetSize() - { - $img = $this->manager()->make('tests/images/tile.png'); - $size = $img->getSize(); - $this->assertInstanceOf('Intervention\Image\Size', $size); - $this->assertInternalType('int', $size->width); - $this->assertInternalType('int', $size->height); - $this->assertEquals(16, $size->width); - $this->assertEquals(16, $size->height); - } - - public function testResizeImage() - { - $img = $this->manager()->make('tests/images/circle.png'); - $img->resize(120, 150); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(120, $img->getWidth()); - $this->assertEquals(150, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testResizeImageOnlyWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(120, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(120, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 15); - } - - public function testResizeImageOnlyHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(null, 150); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(150, $img->getHeight()); - $this->assertTransparentPosition($img, 15, 0); - } - - public function testResizeImageAutoHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(50, null, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertTransparentPosition($img, 30, 0); - } - - public function testResizeImageAutoWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(null, 50, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertTransparentPosition($img, 30, 0); - } - - public function testResizeDominantWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(100, 120, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testResizeImagePreserveSimpleUpsizing() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(100, 100, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 15, 0); - } - - public function testWidenImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->widen(100); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testWidenImageWithConstraint() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->widen(100, function ($constraint) {$constraint->upsize();}); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 8, 0); - } - - public function testHeightenImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->heighten(100); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testHeightenImageWithConstraint() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->heighten(100, function ($constraint) {$constraint->upsize();}); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('resource', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 8, 0); - } - - public function testResizeCanvasCenter() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 5, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 5, 4); - } - - public function testResizeCanvasTopLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top-left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 8, 7); - } - - public function testResizeCanvasTop() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 5, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 5, 7); - } - - public function testResizeCanvasTopRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top-right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 2, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 2, 7); - } - - public function testResizeCanvasLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 8, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 8, 4); - } - - public function testResizeCanvasRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 2, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 2, 4); - } - - public function testResizeCanvasBottomLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom-left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 8, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 8, 1); - } - - public function testResizeCanvasBottomRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom-right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 2, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 2, 1); - } - - public function testResizeCanvasBottom() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 5, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 5, 1); - } - - public function testResizeCanvasRelativeWithBackground() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(4, 4, 'center', true, '#ff00ff'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(20, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#ff00ff', $img, 0, 0); - $this->assertColorAtPosition('#ff00ff', $img, 19, 19); - $this->assertColorAtPosition('#b4e000', $img, 2, 9); - $this->assertColorAtPosition('#445160', $img, 10, 10); - $this->assertTransparentPosition($img, 2, 10); - $this->assertTransparentPosition($img, 10, 9); - } - - public function testResizeCanvasJustWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, null); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 5, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 5, 7); - } - - public function testResizeCanvasJustHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(null, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 8, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 8, 4); - } - - public function testResizeCanvasSmallerWidthLargerHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 20); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 9); - $this->assertColorAtPosition('#445160', $img, 5, 10); - $this->assertTransparentPosition($img, 0, 10); - $this->assertTransparentPosition($img, 5, 9); - } - - public function testResizeCanvasLargerWidthSmallerHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(20, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(20, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 2, 4); - $this->assertColorAtPosition('#445160', $img, 10, 5); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 2, 5); - $this->assertTransparentPosition($img, 10, 4); - } - - public function testResizeCanvasNegative() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(-4, -4); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(12, $img->getWidth()); - $this->assertEquals(12, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 5); - $this->assertColorAtPosition('#445160', $img, 6, 6); - $this->assertTransparentPosition($img, 0, 6); - $this->assertTransparentPosition($img, 6, 5); - } - - public function testResizeCanvasLargerHeightAutoWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(null, 20, 'bottom-left', false, '#ff00ff'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#ff00ff', $img, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#b4e000', $img, 0, 11); - $this->assertColorAtPosition('#445160', $img, 8, 12); - $this->assertTransparentPosition($img, 0, 12); - $this->assertTransparentPosition($img, 8, 11); - } - - public function testResizeCanvasBorderNonRelative() - { - $img = $this->manager()->canvas(1, 1, 'ff0000'); - $img->resizeCanvas(17, 17, 'center', false, '333333'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(17, $img->getWidth()); - $this->assertEquals(17, $img->getHeight()); - $this->assertColorAtPosition('#333333', $img, 0, 0); - $this->assertColorAtPosition('#333333', $img, 5, 5); - $this->assertColorAtPosition('#333333', $img, 7, 7); - $this->assertColorAtPosition('#ff0000', $img, 8, 8); - } - - public function testCropImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->crop(6, 6); // should be centered without pos. - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(6, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445160', $img, 3, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 3, 2); - } - - public function testCropImageWithPosition() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->crop(4, 4, 7, 7); // should be centered without pos. - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(4, $img->getWidth()); - $this->assertEquals(4, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 1, 1); - $this->assertTransparentPosition($img, 0, 1); - $this->assertTransparentPosition($img, 1, 0); - } - - public function testFitImageSquare() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fit(6); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(6, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445060', $img, 3, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 3, 2); - } - - public function testFitImageRectangle() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fit(12, 6); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(12, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445160', $img, 6, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 6, 2); - } - - public function testFitImageWithConstraintUpsize() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->fit(300, 150, function ($constraint) {$constraint->upsize();}); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(25, $img->getHeight()); - $this->assertColorAtPosition('#00aef0', $img, 0, 0); - $this->assertColorAtPosition('#afa94c', $img, 17, 0); - $this->assertColorAtPosition('#ffa601', $img, 24, 0); - } - - public function testFlipImageHorizontal() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->flip('h'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 8, 7); - $this->assertColorAtPosition('#445160', $img, 0, 8); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testFlipImageVertical() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->flip('v'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 7); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testRotateImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->rotate(90); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 7); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testInsertImage() - { - $watermark = $this->manager()->canvas(16, 16, '#0000ff'); // create watermark - - // top-left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(0, 0, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(16, 16, 'hex')); - - // top-left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(9, 9, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(10, 10, 'hex')); - - // top anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 15, 'hex')); - - // top anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(18, 10, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(31, 26, 'hex')); - - // top-right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(15, 0, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(31, 0, 'hex')); - - // top-right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(6, 9, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(21, 25, 'hex')); - - // left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(15, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(0, 7, 'hex')); - - // left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(8, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(10, 7, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(25, 23, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(25, 8, 'hex')); - - // right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(31, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(15, 15, 'hex')); - - // right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(22, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(21, 7, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(6, 8, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(21, 23, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(6, 23, 'hex')); - - // bottom-left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(15, 31, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(0, 15, 'hex')); - - // bottom-left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(10, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(9, 20, 'hex')); - - // bottom anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(8, 16, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 15, 'hex')); - - // bottom anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(23, 22, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(24, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(7, 6, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(8, 6, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 21, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 6, 'hex')); - - // bottom-right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(16, 16, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(15, 16, 'hex')); - - // bottom-right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(21, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(22, 22, 'hex')); - - // center anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'center', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex')); - - // center anchor coordinates / coordinates will be ignored for center - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'center', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex')); - } - - public function testInsertWithAlphaChannel() - { - $img = $this->manager()->canvas(50, 50, 'ff0000'); - $img->insert('tests/images/circle.png'); - $this->assertColorAtPosition('#ff0000', $img, 0, 0); - $this->assertColorAtPosition('#320000', $img, 30, 30); - } - - public function testInsertAfterResize() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->resize(16, 16)->insert('tests/images/tile.png'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#ffa601', $img, 8, 7); - } - - public function testInsertResource() - { - $resource = imagecreatefrompng('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($resource); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testInsertBinary() - { - $data = file_get_contents('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($data); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testInsertInterventionImage() - { - $obj = $this->manager()->make('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($obj); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testOpacity() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->opacity(50); - $checkColor = $img->pickColor(7, 7, 'array'); - $this->assertEquals($checkColor[0], 180); - $this->assertEquals($checkColor[1], 224); - $this->assertEquals($checkColor[2], 0); - $this->assertEquals($checkColor[3], 0.5); - $checkColor = $img->pickColor(8, 8, 'array'); - $this->assertEquals($checkColor[0], 68); - $this->assertEquals($checkColor[1], 81); - $this->assertEquals($checkColor[2], 96); - $this->assertEquals($checkColor[3], 0.5); - $this->assertTransparentPosition($img, 0, 11); - } - - public function testMaskImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->mask('tests/images/gradient.png'); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 23, 23); - $checkColor = $img->pickColor(23, 24, 'array'); - $this->assertEquals($checkColor[0], 255); - $this->assertEquals($checkColor[1], 166); - $this->assertEquals($checkColor[2], 1); - $this->assertEquals($checkColor[3], 0.97); - $checkColor = $img->pickColor(39, 25, 'array'); - $this->assertEquals($checkColor[0], 0); - $this->assertEquals($checkColor[1], 174); - $this->assertEquals($checkColor[2], 240); - $this->assertEquals($checkColor[3], 0.32); - } - - public function testMaskImageWithAlpha() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->mask('tests/images/star.png', true); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 16, 16); - $checkColor = $img->pickColor(18, 18, 'array'); - $this->assertEquals($checkColor[0], 255); - $this->assertEquals($checkColor[1], 166); - $this->assertEquals($checkColor[2], 1); - $this->assertEquals($checkColor[3], 0.65); - $checkColor = $img->pickColor(24, 10, 'array'); - $this->assertEquals($checkColor[0], 0); - $this->assertEquals($checkColor[1], 174); - $this->assertEquals($checkColor[2], 240); - $this->assertEquals($checkColor[3], 0.80); - } - - public function testPixelateImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->pixelate(20); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testGreyscaleImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->greyscale(); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertTransparentPosition($img, 8, 0); - $this->assertColorAtPosition('#b9b9b9', $img, 0, 0); - } - - public function testInvertImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->invert(); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertTransparentPosition($img, 8, 0); - $this->assertColorAtPosition('#4b1fff', $img, 0, 0); - } - - public function testBlurImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->blur(1); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testFillImageWithColor() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fill('b53717'); - $this->assertColorAtPosition('#b53717', $img, 0, 0); - $this->assertColorAtPosition('#b53717', $img, 15, 15); - } - - public function testFillImageWithColorAtPosition() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fill('b53717', 0, 0); - $this->assertTransparentPosition($img, 0, 8); - $this->assertColorAtPosition('#b53717', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 15, 15); - } - - public function testFillImageWithResource() - { - $resource = imagecreatefrompng('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($resource, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testFillImageWithBinary() - { - $data = file_get_contents('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($data, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testFillImageWithInterventionImage() - { - $obj = $this->manager()->make('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($obj, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testPixelImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $coords = [[5, 5], [12, 12]]; - $img = $img->pixel('fdf5e4', $coords[0][0], $coords[0][1]); - $img = $img->pixel([255, 255, 255], $coords[1][0], $coords[1][1]); - $this->assertEquals('#fdf5e4', $img->pickColor($coords[0][0], $coords[0][1], 'hex')); - $this->assertEquals('#ffffff', $img->pickColor($coords[1][0], $coords[1][1], 'hex')); - } - - public function testTextImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img = $img->text('0', 3, 11); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('a9e2b15452b2a4637b65625188d206f6', $img->checksum()); - - - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img = $img->text('0', 8, 2, function($font) { - $font->align('center'); - $font->valign('top'); - $font->color('000000'); - }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('649f3f529d3931c56601155fd2680959', $img->checksum()); - - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img = $img->text('0', 8, 8, function($font) { - $font->align('right'); - $font->valign('middle'); - $font->file(2); - $font->color('000000'); - }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertEquals('c0dda67589c46a90d78a97b891a811ee', $img->checksum()); - } - - public function testRectangleImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->rectangle(5, 5, 11, 11, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('e95487dcc29daf371a0e9190bff8dbfe', $img->checksum()); - } - - public function testLineImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->line(0, 0, 15, 15, function ($draw) { $draw->color('#ff0000'); }); - $this->assertEquals('a6237d34f6e95f30d2fc91a46bd058e6', $img->checksum()); - } - - public function testEllipseImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->ellipse(12, 8, 8, 8, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('080d9dd92ebe22f976c3c703cba33510', $img->checksum()); - } - - public function testCircleImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->circle(12, 8, 8, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('c3bff06c20244ba14e898e39ea0efd76', $img->checksum()); - } - - public function testPolygonImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $points = [3, 3, 11, 11, 7, 13]; - $img->polygon($points, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('e534ff90c8026f9317b99071fda01ed4', $img->checksum()); - } - - public function testResetImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->backup(); - $img->resize(30, 20); - $img->reset(); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - } - - public function testResetEmptyImage() - { - $img = $this->manager()->canvas(16, 16, '#0000ff'); - $img->backup(); - $img->resize(30, 20); - $img->fill('#ff0000'); - $img->reset(); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#0000ff', $img, 0, 0); - } - - public function testResetKeepTransparency() - { - $img = $this->manager()->make('tests/images/circle.png'); - $img->backup(); - $img->reset(); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testResetToNamed() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->backup('original'); - $img->resize(30, 20); - $img->backup('30x20'); - - // reset to original - $img->reset('original'); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - - // reset to 30x20 - // $img->reset('30x20'); - // $this->assertEquals(30, $img->getWidth()); - // $this->assertEquals(20, $img->getHeight()); - - // reset to original again - $img->reset('original'); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - } - - public function testLimitColors() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->limitColors(4); - $this->assertLessThanOrEqual(5, imagecolorstotal($img->getCore())); - } - - public function testLimitColorsKeepTransparency() - { - $img = $this->manager()->make('tests/images/star.png'); - $img->limitColors(16); - $this->assertLessThanOrEqual(17, imagecolorstotal($img->getCore())); - $this->assertTransparentPosition($img, 0, 0); - $this->assertColorAtPosition('#0c02b4', $img, 6, 12); - $this->assertColorAtPosition('#fcbe04', $img, 22, 24); - } - - public function testLimitColorsKeepTransparencyWithMatte() - { - $img = $this->manager()->make('tests/images/star.png'); - $img->limitColors(64, '#00ff00'); - $this->assertLessThanOrEqual(65, imagecolorstotal($img->getCore())); - $this->assertTransparentPosition($img, 0, 0); - $this->assertColorAtPosition('#04f204', $img, 12, 10); - $this->assertColorAtPosition('#e40214', $img, 16, 21); - } - - public function testLimitColorsNullWithMatte() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->limitColors(null, '#ff00ff'); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#ff00ff', $img, 0, 8); - $this->assertColorAtPosition('#ff00ff', $img, 15, 0); - } - - public function testPickColorFromTrueColor() - { - $img = $this->manager()->make('tests/images/star.png'); - $c = $img->pickColor(0, 0); - $this->assertEquals(255, $c[0]); - $this->assertEquals(255, $c[1]); - $this->assertEquals(255, $c[2]); - $this->assertEquals(0, $c[3]); - - $c = $img->pickColor(11, 11); - $this->assertEquals(34, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(160, $c[2]); - $this->assertEquals(0.46, $c[3]); - - $c = $img->pickColor(16, 16); - $this->assertEquals(231, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(18, $c[2]); - $this->assertEquals(1, $c[3]); - } - - public function testPickColorFromIndexed() - { - $img = $this->manager()->make('tests/images/tile.png'); - $c = $img->pickColor(0, 0); - $this->assertEquals(180, $c[0]); - $this->assertEquals(224, $c[1]); - $this->assertEquals(0, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(8, 8); - $this->assertEquals(68, $c[0]); - $this->assertEquals(81, $c[1]); - $this->assertEquals(96, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(0, 15); - $this->assertEquals(255, $c[0]); - $this->assertEquals(255, $c[1]); - $this->assertEquals(255, $c[2]); - $this->assertEquals(0, $c[3]); - } - - public function testPickColorFromPalette() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->limitColors(200); - - $c = $img->pickColor(0, 0); - $this->assertEquals(180, $c[0]); - $this->assertEquals(226, $c[1]); - $this->assertEquals(4, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(8, 8); - $this->assertEquals(68, $c[0]); - $this->assertEquals(82, $c[1]); - $this->assertEquals(100, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(0, 15); - $this->assertEquals(255, $c[0]); - $this->assertEquals(255, $c[1]); - $this->assertEquals(255, $c[2]); - $this->assertEquals(0, $c[3]); - } - - public function testInterlaceImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->interlace(); - $img->encode('png'); - $this->assertTrue((ord($img->encoded[28]) != '0')); - $img->interlace(false); - $img->encode('png'); - $this->assertFalse((ord($img->encoded[28]) != '0')); - } - - public function testGammaImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->gamma(1.6); - $this->assertColorAtPosition('#00c9f6', $img, 0, 0); - $this->assertColorAtPosition('#ffc308', $img, 24, 24); - } - - public function testBrightnessImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->brightness(35); - $this->assertColorAtPosition('#59ffff', $img, 0, 0); - $this->assertColorAtPosition('#ffff5a', $img, 24, 24); - } - - public function testContrastImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->contrast(35); - $this->assertColorAtPosition('#00d4ff', $img, 0, 0); - $this->assertColorAtPosition('#ffc500', $img, 24, 24); - } - - public function testColorizeImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->colorize(40, 25, -50); - $this->assertColorAtPosition('#66ee70', $img, 0, 0); - $this->assertColorAtPosition('#ffe600', $img, 24, 24); - } - - public function testTrimGradient() - { - $canvas = $this->manager()->make('tests/images/gradient.png'); - - $img = clone $canvas; - $img->trim(); - $this->assertEquals($img->getWidth(), 46); - $this->assertEquals($img->getHeight(), 46); - - $img = clone $canvas; - $img->trim(null, null, 10); - $this->assertEquals($img->getWidth(), 38); - $this->assertEquals($img->getHeight(), 38); - - $img = clone $canvas; - $img->trim(null, null, 20); - $this->assertEquals($img->getWidth(), 34); - $this->assertEquals($img->getHeight(), 34); - - $img = clone $canvas; - $img->trim(null, null, 30); - $this->assertEquals($img->getWidth(), 30); - $this->assertEquals($img->getHeight(), 30); - - $img = clone $canvas; - $img->trim(null, null, 40); - $this->assertEquals($img->getWidth(), 26); - $this->assertEquals($img->getHeight(), 26); - - $img = clone $canvas; - $img->trim(null, null, 50); - $this->assertEquals($img->getWidth(), 22); - $this->assertEquals($img->getHeight(), 22); - - $img = clone $canvas; - $img->trim(null, null, 60); - $this->assertEquals($img->getWidth(), 20); - $this->assertEquals($img->getHeight(), 20); - - $img = clone $canvas; - $img->trim(null, null, 70); - $this->assertEquals($img->getWidth(), 16); - $this->assertEquals($img->getHeight(), 16); - - $img = clone $canvas; - $img->trim(null, null, 80); - $this->assertEquals($img->getWidth(), 12); - $this->assertEquals($img->getHeight(), 12); - - $img = clone $canvas; - $img->trim(null, null, 90); - $this->assertEquals($img->getWidth(), 8); - $this->assertEquals($img->getHeight(), 8); - } - - public function testTrimOnlyLeftAndRight() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, ['left', 'right'], 60); - $this->assertEquals($img->getWidth(), 20); - $this->assertEquals($img->getHeight(), 50); - } - - public function testTrimOnlyTopAndBottom() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, ['top', 'bottom'], 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 20); - } - - public function testTrimOnlyTop() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, 'top', 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 35); - } - - public function testTrimOnlyBottom() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, 'top', 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 35); - } - - public function testTrimWithFeather() - { - $canvas = $this->manager()->make('tests/images/trim.png'); - - $img = clone $canvas; - $feather = 5; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - - $img = clone $canvas; - $feather = 10; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - - $img = clone $canvas; - $feather = 20; // must respect original dimensions of image - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 50); - - $img = clone $canvas; - $feather = -5; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - - $img = clone $canvas; - $feather = -10; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - - // trim only left and right with feather - $img = clone $canvas; - $feather = 10; - $img->trim(null, ['left', 'right'], null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 50); - - // trim only top and bottom with feather - $img = clone $canvas; - $feather = 10; - $img->trim(null, ['top', 'bottom'], null, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - - // trim with tolerance and feather - $canvas = $this->manager()->make('tests/images/gradient.png'); - - $img = clone $canvas; - $feather = 2; - $img->trim(null, null, 10, $feather); - $this->assertEquals($img->getWidth(), 38 + $feather * 2); - $this->assertEquals($img->getHeight(), 38 + $feather * 2); - - $img = clone $canvas; - $feather = 5; - $img->trim(null, null, 10, $feather); - $this->assertEquals($img->getWidth(), 38 + $feather * 2); - $this->assertEquals($img->getHeight(), 38 + $feather * 2); - - $img = clone $canvas; - $feather = 10; // should respect original dimensions - $img->trim(null, null, 20, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 50); - } - - public function testEncodeDefault() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode(); - $this->assertInternalType('resource', imagecreatefromstring($img->encoded)); - } - - public function testEncodeJpeg() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('jpg'); - $this->assertInternalType('resource', imagecreatefromstring($img->encoded)); - } - - public function testEncodeGif() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('gif'); - $this->assertInternalType('resource', imagecreatefromstring($img->encoded)); - } - - public function testEncodeWebp() - { - if (function_exists('imagewebp')) { - $img = $this->manager()->make('tests/images/trim.png'); - $data = (string) $img->encode('webp'); - $this->assertEquals('image/webp; charset=binary', $this->getMime($data)); - } - } - - public function testEncodeDataUrl() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('data-url'); - $this->assertEquals('data:image/png;base64', substr($img->encoded, 0, 21)); - } - - public function testExifReadAll() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif(); - $this->assertInternalType('array', $data); - $this->assertEquals(19, count($data)); - } - - public function testExifReadKey() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif('Artist'); - $this->assertInternalType('string', $data); - $this->assertEquals('Oliver Vogel', $data); - } - - public function testExifReadNotExistingKey() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif('xxx'); - $this->assertEquals(null, $data); - } - - public function testSaveImage() - { - $save_as = 'tests/tmp/foo.jpg'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as, 80); - $this->assertFileExists($save_as); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.jpg'); - $this->assertEquals($img->extension, 'jpg'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/jpeg'); - @unlink($save_as); - - $save_as = 'tests/tmp/foo.png'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.png'); - $this->assertEquals($img->extension, 'png'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/png'); - $this->assertFileExists($save_as); - @unlink($save_as); - - $save_as = 'tests/tmp/foo.jpg'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as, 0); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.jpg'); - $this->assertEquals($img->extension, 'jpg'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/jpeg'); - $this->assertFileExists($save_as); - @unlink($save_as); - } - - public function testSaveImageWithoutParameter() - { - $path = 'tests/tmp/bar.png'; - - // create temp. test image (red) - $img = $this->manager()->canvas(16, 16, '#ff0000'); - $img->save($path); - $img->destroy(); - - // open test image again - $img = $this->manager()->make($path); - $this->assertColorAtPosition('#ff0000', $img, 0, 0); - - // fill with green and save wthout paramater - $img->fill('#00ff00'); - $img->save(); - $img->destroy(); - - // re-open test image (should be green) - $img = $this->manager()->make($path); - $this->assertColorAtPosition('#00ff00', $img, 0, 0); - $img->destroy(); - - @unlink($path); - } - - public function testDestroy() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->backup(); - $img->destroy(); - // destroy should affect core - $this->assertEquals(get_resource_type($img->getCore()), 'Unknown'); - // destroy should affect backup - $this->assertEquals(get_resource_type($img->getBackup()), 'Unknown'); - } - - public function testStringConversion() - { - $img = $this->manager()->make('tests/images/trim.png'); - $value = strval($img); - $this->assertInternalType('string', $value); - } - - public function testFilter() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->filter(new \Intervention\Image\Filters\DemoFilter(10)); - $this->assertColorAtPosition('#818181', $img, 0, 0); - $this->assertColorAtPosition('#939393', $img, 18, 18); - $this->assertColorAtPosition('#939393', $img, 18, 18); - $this->assertColorAtPosition('#adadad', $img, 25, 25); - $this->assertColorAtPosition('#939393', $img, 35, 35); - } - - public function testCloneImageObject() - { - $img = $this->manager()->make('tests/images/trim.png'); - $cln = clone $img; - - // destroy original - $img->destroy(); - unset($img); - - // clone should be still intact - $this->assertInstanceOf('Intervention\Image\Image', $cln); - $this->assertInternalType('resource', $cln->getCore()); - } - - public function testGifConversionKeepsTransparency() - { - $save_as = 'tests/tmp/foo.gif'; - - // create gif image from transparent png - $img = $this->manager()->make('tests/images/star.png'); - $img->save($save_as); - - // new gif image should be transparent - $img = $this->manager()->make($save_as); - $this->assertTransparentPosition($img, 0, 0); - @unlink($save_as); - } - - private function assertColorAtPosition($color, $img, $x, $y) - { - $pick = $img->pickColor($x, $y, 'hex'); - $this->assertEquals($color, $pick); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - private function assertTransparentPosition($img, $x, $y, $transparent = 0) - { - // background should be transparent - $color = $img->pickColor($x, $y, 'array'); - $this->assertEquals($transparent, $color[3]); // alpha channel - } - - private function manager() - { - return new \Intervention\Image\ImageManager([ - 'driver' => 'gd' - ]); - } - - private function getMime($data) - { - $finfo = new finfo(FILEINFO_MIME); - return $finfo->buffer($data); - } -} diff --git a/tests/Geometry/PointTest.php b/tests/Geometry/PointTest.php new file mode 100644 index 00000000..f2d15b2e --- /dev/null +++ b/tests/Geometry/PointTest.php @@ -0,0 +1,82 @@ +assertInstanceOf(Point::class, $point); + $this->assertEquals(0, $point->getX()); + $this->assertEquals(0, $point->getY()); + } + + public function testConstructorWithParameters() + { + $point = new Point(40, 50); + $this->assertInstanceOf(Point::class, $point); + $this->assertEquals(40, $point->getX()); + $this->assertEquals(50, $point->getY()); + } + + public function testSetX() + { + $point = new Point(0, 0); + $point->setX(100); + $this->assertEquals(100, $point->getX()); + $this->assertEquals(0, $point->getY()); + } + + public function testSetY() + { + $point = new Point(0, 0); + $point->setY(100); + $this->assertEquals(0, $point->getX()); + $this->assertEquals(100, $point->getY()); + } + + public function testmoveX() + { + $point = new Point(50, 50); + $point->moveX(100); + $this->assertEquals(150, $point->getX()); + $this->assertEquals(50, $point->getY()); + } + + public function testmoveY() + { + $point = new Point(50, 50); + $point->moveY(100); + $this->assertEquals(50, $point->getX()); + $this->assertEquals(150, $point->getY()); + } + + public function testSetPosition() + { + $point = new Point(0, 0); + $point->setPosition(100, 200); + $this->assertEquals(100, $point->getX()); + $this->assertEquals(200, $point->getY()); + } + + public function testRotate() + { + $point = new Point(30, 0); + $point->rotate(90, new Point(0, 0)); + $this->assertEquals(0, $point->getX()); + $this->assertEquals(30, $point->getY()); + + $point->rotate(90, new Point(0, 0)); + $this->assertEquals(-30, $point->getX()); + $this->assertEquals(0, $point->getY()); + + $point = new Point(300, 200); + $point->rotate(90, new Point(0, 0)); + $this->assertEquals(-200, $point->getX()); + $this->assertEquals(300, $point->getY()); + } +} diff --git a/tests/Geometry/SizeTest.php b/tests/Geometry/SizeTest.php new file mode 100644 index 00000000..e3e9c348 --- /dev/null +++ b/tests/Geometry/SizeTest.php @@ -0,0 +1,101 @@ +assertInstanceOf(Size::class, $size); + $this->assertInstanceOf(Point::class, $size->getPivot()); + $this->assertEquals(300, $size->getWidth()); + $this->assertEquals(200, $size->getHeight()); + } + + public function testGetWidth() + { + $size = new Size(800, 600); + $this->assertEquals(800, $size->getWidth()); + } + + public function testGetHeight() + { + $size = new Size(800, 600); + $this->assertEquals(600, $size->getHeight()); + } + + public function testGetAspectRatio() + { + $size = new Size(800, 600); + $this->assertEquals(1.33333333333, $size->getAspectRatio()); + + $size = new Size(100, 100); + $this->assertEquals(1, $size->getAspectRatio()); + + $size = new Size(1920, 1080); + $this->assertEquals(1.777777777778, $size->getAspectRatio()); + } + + public function testFitsInto() + { + $box = new Size(800, 600); + $fits = $box->fitsInto(new Size(100, 100)); + $this->assertFalse($fits); + + $box = new Size(800, 600); + $fits = $box->fitsInto(new Size(1000, 100)); + $this->assertFalse($fits); + + $box = new Size(800, 600); + $fits = $box->fitsInto(new Size(100, 1000)); + $this->assertFalse($fits); + + $box = new Size(800, 600); + $fits = $box->fitsInto(new Size(800, 600)); + $this->assertTrue($fits); + + $box = new Size(800, 600); + $fits = $box->fitsInto(new Size(1000, 1000)); + $this->assertTrue($fits); + + $box = new Size(100, 100); + $fits = $box->fitsInto(new Size(800, 600)); + $this->assertTrue($fits); + + $box = new Size(100, 100); + $fits = $box->fitsInto(new Size(80, 60)); + $this->assertFalse($fits); + } + + public function testIsLandscape() + { + $box = new Size(100, 100); + $this->assertFalse($box->isLandscape()); + + $box = new Size(100, 200); + $this->assertFalse($box->isLandscape()); + + $box = new Size(300, 200); + $this->assertTrue($box->isLandscape()); + } + + public function testIsPortrait() + { + $box = new Size(100, 100); + $this->assertFalse($box->isPortrait()); + + $box = new Size(200, 100); + $this->assertFalse($box->isPortrait()); + + $box = new Size(200, 300); + $this->assertTrue($box->isPortrait()); + } +} diff --git a/tests/GetsizeCommandTest.php b/tests/GetsizeCommandTest.php deleted file mode 100644 index d67f3b7f..00000000 --- a/tests/GetsizeCommandTest.php +++ /dev/null @@ -1,39 +0,0 @@ -shouldReceive('getCore')->times(2)->andReturn($resource); - $command = new GetSizeGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInstanceOf('Intervention\Image\Size', $command->getOutput()); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getimagewidth')->with(); - $imagick->shouldReceive('getimageheight')->with(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new GetSizeImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInstanceOf('Intervention\Image\Size', $command->getOutput()); - } -} diff --git a/tests/GreyscaleCommandTest.php b/tests/GreyscaleCommandTest.php deleted file mode 100644 index 84298199..00000000 --- a/tests/GreyscaleCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new GreyscaleGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('modulateimage')->with(100, 0, 100)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new GreyscaleImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/HeightenCommandTest.php b/tests/HeightenCommandTest.php deleted file mode 100644 index 4016ff7d..00000000 --- a/tests/HeightenCommandTest.php +++ /dev/null @@ -1,49 +0,0 @@ -aspectRatio(); }; - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(800); - $size->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new HeightenGd([200]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $callback = function ($constraint) { $constraint->upsize(); }; - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('scaleimage')->with(300, 200)->once()->andReturn(true); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(300); - $size->shouldReceive('getHeight')->once()->andReturn(200); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('getSize')->once()->andReturn($size); - $command = new HeightenImagick([200]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/ImageManagerStaticTest.php b/tests/ImageManagerStaticTest.php deleted file mode 100644 index b4bb3f5d..00000000 --- a/tests/ImageManagerStaticTest.php +++ /dev/null @@ -1,36 +0,0 @@ -getManager(); - $this->assertInstanceOf('Intervention\Image\ImageManager', $m); - } - - public function testMake() - { - $manager = Mockery::mock('Intervention\Image\ImageManager'); - $manager->shouldReceive('make')->with('foo')->once(); - $managerStatic = new ImageManagerStatic($manager); - $managerStatic->make('foo'); - } - - public function testCanvas() - { - $manager = Mockery::mock('Intervention\Image\ImageManager'); - $manager->shouldReceive('canvas')->with(100, 100, null)->once(); - $managerStatic = new ImageManagerStatic($manager); - $managerStatic->canvas(100, 100); - } -} diff --git a/tests/ImageManagerTest.php b/tests/ImageManagerTest.php index 9312208a..2bdd2c6e 100644 --- a/tests/ImageManagerTest.php +++ b/tests/ImageManagerTest.php @@ -1,40 +1,46 @@ 'foo', 'bar' => 'baz']; - $manager = new ImageManager($config); - $this->assertEquals('foo', $manager->config['driver']); - $this->assertEquals('baz', $manager->config['bar']); + $manager = new ImageManager(['foo' => 'bar']); + $this->assertInstanceOf(ImageManager::class, $manager); + $this->assertEquals('gd', $manager->getConfig('driver')); + $this->assertEquals('bar', $manager->getConfig('foo')); } public function testConfigure() { - $overwrite = ['driver' => 'none', 'bar' => 'none']; - $config = ['driver' => 'foo', 'bar' => 'baz']; - $manager = new ImageManager($overwrite); - $manager->configure($config); - $this->assertEquals('foo', $manager->config['driver']); - $this->assertEquals('baz', $manager->config['bar']); + $manager = new ImageManager(['foo' => 'bar']); + $manager->configure(['foo' => 'baz', 'driver' => 'foo']); + $this->assertEquals('foo', $manager->getConfig('driver')); + $this->assertEquals('baz', $manager->getConfig('foo')); } - public function testConfigureObject() + public function testGetConfig() { - $config = ['driver' => new Intervention\Image\Imagick\Driver()]; - $manager = new ImageManager($config); + $manager = new ImageManager(['foo' => 'bar']); + $this->assertEquals('gd', $manager->getConfig('driver')); + $this->assertEquals('bar', $manager->getConfig('foo')); + } - $image = $manager->make('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); - $this->assertInstanceOf('Intervention\Image\Image', $image); - $this->assertInstanceOf('Imagick', $image->getCore()); + public function testCreateGd() + { + $manager = new ImageManager(['driver' => 'gd']); + $image = $manager->create(5, 4); + $this->assertInstanceOf(ImageInterface::class, $image); + } + + public function testMakeGd() + { + $manager = new ImageManager(['driver' => 'gd']); + $image = $manager->make(__DIR__ . '/images/red.gif'); + $this->assertInstanceOf(ImageInterface::class, $image); } } diff --git a/tests/ImageTest.php b/tests/ImageTest.php deleted file mode 100644 index 870658cf..00000000 --- a/tests/ImageTest.php +++ /dev/null @@ -1,143 +0,0 @@ -getTestImage(); - $this->assertEquals('mock', $image->getCore()); - } - - public function testCommandCall() - { - $image = $this->getTestImage(); - $result = $image->test(1, 2, 3); - $this->assertEquals('mock', $result); - } - - public function testEncode() - { - $image = $this->getTestImage(); - $image->getDriver()->shouldReceive('encode')->with($image, 'png', 90)->once(); - $image->encode('png', 90); - } - - public function testSave() - { - $save_as = __DIR__.'/tmp/test.jpg'; - $image = $this->getTestImage(); - $image->getDriver()->shouldReceive('encode')->with($image, 'jpg', 85)->once()->andReturn('mock'); - $image = $image->save($save_as, 85); - $this->assertInstanceOf('\Intervention\Image\Image', $image); - $this->assertFileExists($save_as); - $this->assertEquals($image->basename, 'test.jpg'); - $this->assertEquals($image->extension, 'jpg'); - $this->assertEquals($image->filename, 'test'); - @unlink($save_as); - } - - public function testFormatSave() - { - $save_as = __DIR__.'/tmp/test'; - - $config = ['driver' => new Intervention\Image\Imagick\Driver()]; - $manager = new ImageManager($config); - - $image = $manager->make('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); - $this->assertInstanceOf('Intervention\Image\Image', $image); - $this->assertInstanceOf('Imagick', $image->getCore()); - - $gifCore = $image->getCore(); - $this->assertEquals($gifCore->getImageMimeType(), 'image/gif'); - $image->save($save_as, null, 'jpg'); - - $this->assertEquals(\mime_content_type($save_as), 'image/jpeg'); - @unlink($save_as); - } - - public function testIsEncoded() - { - $image = $this->getTestImage(); - $this->assertFalse($image->isEncoded()); - - $image->setEncoded('foo'); - $this->assertTrue($image->isEncoded()); - } - - public function testFilter() - { - $demoFilter = Mockery::mock('\Intervention\Image\Filters\DemoFilter', [15]); - $image = $this->getTestImage(); - $demoFilter->shouldReceive('applyFilter')->with($image)->once()->andReturn($image); - $image->filter($demoFilter); - } - - public function testMime() - { - $image = $this->getTestImage(); - $this->assertEquals('image/png', $image->mime()); - } - - /** - * @expectedException \Intervention\Image\Exception\RuntimeException - */ - public function testGetBackupWithoutBackuo() - { - $image = $this->getTestImage(); - $image->getBackup(); - } - - public function testSetGetBackup() - { - $image = $this->getTestImage(); - $image->setBackup('foo'); - $backup = $image->getBackup(); - $this->assertEquals('foo', $backup); - } - - public function testGetBackups() - { - $image = $this->getTestImage(); - $backups = $image->getBackups(); - $this->assertEquals([], $backups); - - $image = $this->getTestImage(); - $image->setBackup('foo'); - $image->setBackup('bar'); - $image->setBackup('baz'); - $backups = $image->getBackups(); - $this->assertEquals(['default' => 'baz'], $backups); - - $image = $this->getTestImage(); - $image->setBackup('foo', 'a'); - $image->setBackup('bar', 'b'); - $image->setBackup('baz', 'c'); - $backups = $image->getBackups(); - $this->assertEquals(['a' => 'foo', 'b' => 'bar', 'c' => 'baz'], $backups); - } - - private function getTestImage() - { - $size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $driver = Mockery::mock('\Intervention\Image\AbstractDriver'); - $command = Mockery::mock('\Intervention\Image\Commands\AbstractCommand'); - $command->shouldReceive('hasOutput')->andReturn(true); - $command->shouldReceive('getOutput')->andReturn('mock'); - $driver->shouldReceive('executeCommand')->andReturn($command); - $image = new Image($driver, 'mock'); - $image->mime = 'image/png'; - $image->dirname = './tmp'; - $image->basename = 'foo.png'; - - return $image; - } -} diff --git a/tests/ImagickColorTest.php b/tests/ImagickColorTest.php deleted file mode 100644 index c51ec4da..00000000 --- a/tests/ImagickColorTest.php +++ /dev/null @@ -1,338 +0,0 @@ -pixel = Mockery::mock('ImagickPixel'); - $c->pixel->shouldReceive('getcolorvalue')->with(Imagick::COLOR_RED)->andReturn(0.956862745098); - $this->assertEquals(244, $c->getRedValue()); - - $c = new Color; - $c->pixel = Mockery::mock('ImagickPixel'); - $c->pixel->shouldReceive('getcolorvalue')->with(Imagick::COLOR_GREEN)->andReturn(0.0470588235294); - $this->assertEquals(12, $c->getGreenValue()); - - $c = new Color; - $c->pixel = Mockery::mock('ImagickPixel'); - $c->pixel->shouldReceive('getcolorvalue')->with(Imagick::COLOR_BLUE)->andReturn(0.0862745098039); - $this->assertEquals(22, $c->getBlueValue()); - - $c = new Color; - $c->pixel = Mockery::mock('ImagickPixel'); - $c->pixel->shouldReceive('getcolorvalue')->with(Imagick::COLOR_ALPHA)->andReturn(1); - $this->assertEquals(1, $c->getAlphaValue()); - - $c = new Color; - $c->pixel = Mockery::mock('ImagickPixel'); - $c->pixel->shouldReceive('getcolorvalue')->with(Imagick::COLOR_ALPHA)->andReturn(1); - $this->assertEquals(1, $c->getAlphaValue()); - } - - public function testConstructor() - { - $c = new Color; - $this->validateColor($c, 255, 255, 255, 0); - } - - public function testParseNull() - { - $c = new Color; - $c->parse(null); - $this->validateColor($c, 255, 255, 255, 0); - } - - public function testParseInteger() - { - $c = new Color; - $c->parse(16777215); - $this->validateColor($c, 255, 255, 255, 0); - - $c = new Color; - $c->parse(4294967295); - $this->validateColor($c, 255, 255, 255, 1); - } - - public function testParseArray() - { - $c = new Color; - $c->parse([181, 55, 23, 0.5]); - $this->validateColor($c, 181, 55, 23, 0.5); - } - - public function testParseHexString() - { - $c = new Color; - $c->parse('#b53717'); - $this->validateColor($c, 181, 55, 23, 1); - } - - public function testParseRgbaString() - { - $c = new Color; - $c->parse('rgba(181, 55, 23, 1)'); - $this->validateColor($c, 181, 55, 23, 1); - } - - public function testInitFromInteger() - { - $c = new Color; - $c->initFromInteger(0); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromInteger(2147483647); - $this->validateColor($c, 255, 255, 255, 0.5); - $c->initFromInteger(16777215); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromInteger(2130706432); - $this->validateColor($c, 0, 0, 0, 0.5); - $c->initFromInteger(867514135); - $this->validateColor($c, 181, 55, 23, 0.2); - } - - public function testInitFromArray() - { - $c = new Color; - $c->initFromArray([0, 0, 0, 0]); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromArray([0, 0, 0, 1]); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromArray([255, 255, 255, 1]); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromArray([255, 255, 255, 0]); - $this->validateColor($c, 255, 255, 255, 0); - $c->initFromArray([255, 255, 255, 0.5]); - $this->validateColor($c, 255, 255, 255, 0.5); - $c->initFromArray([0, 0, 0]); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromArray([255, 255, 255]); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromArray([181, 55, 23]); - $this->validateColor($c, 181, 55, 23, 1); - $c->initFromArray([181, 55, 23, 0.5]); - $this->validateColor($c, 181, 55, 23, 0.5); - } - - public function testInitFromHexString() - { - $c = new Color; - $c->initFromString('#cccccc'); - $this->validateColor($c, 204, 204, 204, 1); - $c->initFromString('#b53717'); - $this->validateColor($c, 181, 55, 23, 1); - $c->initFromString('ffffff'); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromString('ff00ff'); - $this->validateColor($c, 255, 0, 255, 1); - $c->initFromString('#000'); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromString('000'); - $this->validateColor($c, 0, 0, 0, 1); - } - - public function testInitFromRgbString() - { - $c = new Color; - $c->initFromString('rgb(1, 14, 144)'); - $this->validateColor($c, 1, 14, 144, 1); - $c->initFromString('rgb (255, 255, 255)'); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromString('rgb(0,0,0)'); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromString('rgba(0,0,0,0)'); - $this->validateColor($c, 0, 0, 0, 0); - $c->initFromString('rgba(0,0,0,0.5)'); - $this->validateColor($c, 0, 0, 0, 0.5); - $c->initFromString('rgba(255, 0, 0, 0.5)'); - $this->validateColor($c, 255, 0, 0, 0.5); - $c->initFromString('rgba(204, 204, 204, 0.9)'); - $this->validateColor($c, 204, 204, 204, 0.9); - } - - public function testInitFromRgb() - { - $c = new Color; - $c->initFromRgb(0, 0, 0); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromRgb(255, 255, 255); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromRgb(181, 55, 23); - $this->validateColor($c, 181, 55, 23, 1); - } - - public function testInitFromRgba() - { - $c = new Color; - $c->initFromRgba(0, 0, 0, 1); - $this->validateColor($c, 0, 0, 0, 1); - $c->initFromRgba(255, 255, 255, 1); - $this->validateColor($c, 255, 255, 255, 1); - $c->initFromRgba(181, 55, 23, 1); - $this->validateColor($c, 181, 55, 23, 1); - $c->initFromRgba(181, 55, 23, 0); - $this->validateColor($c, 181, 55, 23, 0); - $c->initFromRgba(181, 55, 23, 0.5); - $this->validateColor($c, 181, 55, 23, 0.5); - } - - public function testGetInt() - { - $c = new Color; - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 16777215); - - $c = new Color([255, 255, 255]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 4294967295); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 4294967295); - - $c = new Color([181, 55, 23, 0.2]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 867514135); - - $c = new Color([255, 255, 255, 0.5]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 2164260863); - - $c = new Color([181, 55, 23, 1]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 4290066199); - - $c = new Color([0, 0, 0, 0]); - $i = $c->getInt(); - $this->assertInternalType('int', $i); - $this->assertEquals($i, 0); - } - - public function testGetHex() - { - $c = new Color; - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'ffffff'); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'ffffff'); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getHex(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'b53717'); - - $c = new Color([0, 0, 0, 0]); - $i = $c->getHex('#'); - $this->assertInternalType('string', $i); - $this->assertEquals($i, '#000000'); - } - - public function testGetArray() - { - $c = new Color; - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [255, 255, 255, 0]); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [255, 255, 255, 1]); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [181, 55, 23, 0.5]); - - $c = new Color([0, 0, 0, 1]); - $i = $c->getArray(); - $this->assertInternalType('array', $i); - $this->assertEquals($i, [0, 0, 0, 1]); - } - - public function testGetRgba() - { - $c = new Color; - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(255, 255, 255, 0.00)'); - - $c = new Color([255, 255, 255, 1]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(255, 255, 255, 1.00)'); - - $c = new Color([181, 55, 23, 0.5]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(181, 55, 23, 0.50)'); - - $c = new Color([0, 0, 0, 1]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(0, 0, 0, 1.00)'); - - $c = new Color([255, 255, 255, 0.5]); - $i = $c->getRgba(); - $this->assertInternalType('string', $i); - $this->assertEquals($i, 'rgba(255, 255, 255, 0.50)'); - } - - public function testDiffers() - { - $c1 = new Color([0, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2)); - - $c1 = new Color([1, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(true, $c1->differs($c2)); - - $c1 = new Color([1, 0, 0]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2, 10)); - - $c1 = new Color([127, 127, 127]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(true, $c1->differs($c2, 49)); - - $c1 = new Color([127, 127, 127]); - $c2 = new Color([0, 0, 0]); - $this->assertEquals(false, $c1->differs($c2, 50)); - } - - /** - * @expectedException \Intervention\Image\Exception\NotReadableException - */ - public function testParseUnknown() - { - $c = new Color('xxxxxxxxxxxxxxxxxxxx'); - } - - private function validateColor($obj, $r, $g, $b, $a) - { - $this->assertInstanceOf('Intervention\Image\Imagick\Color', $obj); - $this->assertInstanceOf('ImagickPixel', $obj->pixel); - $this->assertEquals($r, round($obj->getRedValue(), 2)); - $this->assertEquals($g, round($obj->getGreenValue(), 2)); - $this->assertEquals($b, round($obj->getBlueValue(), 2)); - $this->assertEquals($a, round($obj->getAlphaValue(), 2)); - } -} diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php deleted file mode 100644 index 25e961c6..00000000 --- a/tests/ImagickSystemTest.php +++ /dev/null @@ -1,1650 +0,0 @@ -manager()->make('tests/images/circle.png'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - $this->assertEquals('tests/images', $img->dirname); - $this->assertEquals('circle.png', $img->basename); - $this->assertEquals('png', $img->extension); - $this->assertEquals('circle', $img->filename); - $this->assertEquals('image/png', $img->mime); - } - - public function testMakeFromString() - { - $str = file_get_contents('tests/images/circle.png'); - $img = $this->manager()->make($str); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - } - - public function testMakeFromImagick() - { - $imagick = new \Imagick; - $imagick->readImage('tests/images/circle.png'); - $img = $this->manager()->make($imagick); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - } - - public function testMakeFromDataUrl() - { - $str = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC'; - $img = $this->manager()->make($str); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - } - - public function testMakeFromBase64() - { - $str = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC'; - $img = $this->manager()->make($str); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - } - - public function testMakeFromBase64WithNewlines() - { - $data = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . - '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . - 'cRvs4UAAAAAElFTkSuQmCC'; - - $img = $this->manager()->make($data); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertEquals('image/png', $img->mime); - } - - - public function testCanvas() - { - $img = $this->manager()->canvas(30, 20); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(30, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testCanvasWithSolidBackground() - { - $img = $this->manager()->canvas(30, 20, 'b53717'); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(30, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertEquals('#b53717', $img->pickColor(15, 15, 'hex')); - } - - public function testGetSize() - { - $img = $this->manager()->make('tests/images/tile.png'); - $size = $img->getSize(); - $this->assertInstanceOf('Intervention\Image\Size', $size); - $this->assertInternalType('int', $size->width); - $this->assertInternalType('int', $size->height); - $this->assertEquals(16, $size->width); - $this->assertEquals(16, $size->height); - } - - public function testResizeImage() - { - $img = $this->manager()->make('tests/images/circle.png'); - $img->resize(120, 150); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(120, $img->getWidth()); - $this->assertEquals(150, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testResizeImageOnlyWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(120, null); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(120, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 0, 15); - } - - public function testResizeImageOnlyHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(null, 150); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(150, $img->getHeight()); - $this->assertTransparentPosition($img, 15, 0); - } - - public function testResizeImageAutoHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(50, null, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertTransparentPosition($img, 30, 0); - } - - public function testResizeImageAutoWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(null, 50, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(50, $img->getHeight()); - $this->assertTransparentPosition($img, 30, 0); - } - - public function testResizeDominantWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(100, 120, function ($constraint) { $constraint->aspectRatio(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testResizeImagePreserveSimpleUpsizing() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resize(100, 100, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 15, 0); - } - - public function testWidenImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->widen(100); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testWidenImageWithConstraint() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->widen(100, function ($constraint) {$constraint->upsize();}); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 8, 0); - } - - public function testHeightenImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->heighten(100); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(100, $img->getWidth()); - $this->assertEquals(100, $img->getHeight()); - $this->assertTransparentPosition($img, 60, 0); - } - - public function testHeightenImageWithConstraint() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->heighten(100, function ($constraint) {$constraint->upsize();}); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInstanceOf('Imagick', $img->getCore()); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertTransparentPosition($img, 8, 0); - } - - public function testResizeCanvasCenter() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 5, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 5, 4); - } - - public function testResizeCanvasTopLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top-left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 8, 7); - } - - public function testResizeCanvasTop() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 5, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 5, 7); - } - - public function testResizeCanvasTopRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'top-right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 2, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 2, 7); - } - - public function testResizeCanvasLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 8, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 8, 4); - } - - public function testResizeCanvasRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 2, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 2, 4); - } - - public function testResizeCanvasBottomLeft() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom-left'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 8, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 8, 1); - } - - public function testResizeCanvasBottomRight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom-right'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 2, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 2, 1); - } - - public function testResizeCanvasBottom() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 10, 'bottom'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 1); - $this->assertColorAtPosition('#445160', $img, 5, 2); - $this->assertTransparentPosition($img, 0, 2); - $this->assertTransparentPosition($img, 5, 1); - } - - public function testResizeCanvasRelativeWithBackground() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(4, 4, 'center', true, '#ff00ff'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(20, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#ff00ff', $img, 0, 0); - $this->assertColorAtPosition('#ff00ff', $img, 19, 19); - $this->assertColorAtPosition('#b4e000', $img, 2, 9); - $this->assertColorAtPosition('#445160', $img, 10, 10); - $this->assertTransparentPosition($img, 2, 10); - $this->assertTransparentPosition($img, 10, 9); - } - - public function testResizeCanvasJustWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, null); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#445160', $img, 5, 8); - $this->assertTransparentPosition($img, 0, 8); - $this->assertTransparentPosition($img, 5, 7); - } - - public function testResizeCanvasJustHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(null, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#445160', $img, 8, 5); - $this->assertTransparentPosition($img, 0, 5); - $this->assertTransparentPosition($img, 8, 4); - } - - public function testResizeCanvasSmallerWidthLargerHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(10, 20); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(10, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 9); - $this->assertColorAtPosition('#445160', $img, 5, 10); - $this->assertTransparentPosition($img, 0, 10); - $this->assertTransparentPosition($img, 5, 9); - } - - public function testResizeCanvasLargerWidthSmallerHeight() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(20, 10); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(20, $img->getWidth()); - $this->assertEquals(10, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 2, 4); - $this->assertColorAtPosition('#445160', $img, 10, 5); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 2, 5); - $this->assertTransparentPosition($img, 10, 4); - } - - public function testResizeCanvasNegative() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(-4, -4); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(12, $img->getWidth()); - $this->assertEquals(12, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 5); - $this->assertColorAtPosition('#445160', $img, 6, 6); - $this->assertTransparentPosition($img, 0, 6); - $this->assertTransparentPosition($img, 6, 5); - } - - public function testResizeCanvasLargerHeightAutoWidth() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->resizeCanvas(null, 20, 'bottom-left', false, '#ff00ff'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - $this->assertColorAtPosition('#ff00ff', $img, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 4); - $this->assertColorAtPosition('#b4e000', $img, 0, 11); - $this->assertColorAtPosition('#445160', $img, 8, 12); - $this->assertTransparentPosition($img, 0, 12); - $this->assertTransparentPosition($img, 8, 11); - } - - public function testResizeCanvasBorderNonRelative() - { - $img = $this->manager()->canvas(1, 1, 'ff0000'); - $img->resizeCanvas(17, 17, 'center', false, '333333'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(17, $img->getWidth()); - $this->assertEquals(17, $img->getHeight()); - $this->assertColorAtPosition('#333333', $img, 0, 0); - $this->assertColorAtPosition('#333333', $img, 5, 5); - $this->assertColorAtPosition('#333333', $img, 7, 7); - $this->assertColorAtPosition('#ff0000', $img, 8, 8); - } - - public function testCropImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->crop(6, 6); // should be centered without pos. - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(6, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445160', $img, 3, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 3, 2); - } - - public function testCropImageWithPosition() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->crop(4, 4, 7, 7); // should be centered without pos. - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(4, $img->getWidth()); - $this->assertEquals(4, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 1, 1); - $this->assertTransparentPosition($img, 0, 1); - $this->assertTransparentPosition($img, 1, 0); - } - - public function testFitImageSquare() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fit(6); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(6, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445160', $img, 3, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 3, 2); - } - - public function testFitImageRectangle() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fit(12, 6); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(12, $img->getWidth()); - $this->assertEquals(6, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 2); - $this->assertColorAtPosition('#445160', $img, 6, 3); - $this->assertTransparentPosition($img, 0, 3); - $this->assertTransparentPosition($img, 6, 2); - } - - public function testFitImageWithConstraintUpsize() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->fit(300, 150, function ($constraint) {$constraint->upsize();}); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(50, $img->getWidth()); - $this->assertEquals(25, $img->getHeight()); - $this->assertColorAtPosition('#00aef0', $img, 0, 0); - $this->assertColorAtPosition('#afa94c', $img, 17, 0); - $this->assertColorAtPosition('#ffa601', $img, 24, 0); - } - - public function testFlipImageHorizontal() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->flip('h'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 8, 7); - $this->assertColorAtPosition('#445160', $img, 0, 8); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testFlipImageVertical() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->flip('v'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 7); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testRotateImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->rotate(90); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 7); - $this->assertTransparentPosition($img, 0, 7); - $this->assertTransparentPosition($img, 8, 8); - } - - public function testInsertImage() - { - $watermark = $this->manager()->canvas(16, 16, '#0000ff'); // create watermark - - // top-left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(0, 0, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(16, 16, 'hex')); - - // top-left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(9, 9, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(10, 10, 'hex')); - - // top anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 15, 'hex')); - - // top anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(18, 10, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(31, 26, 'hex')); - - // top-right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(15, 0, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(31, 0, 'hex')); - - // top-right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'top-right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(6, 9, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(21, 25, 'hex')); - - // left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(15, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(0, 7, 'hex')); - - // left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(8, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(10, 7, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(25, 23, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(25, 8, 'hex')); - - // right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(31, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(15, 15, 'hex')); - - // right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(22, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(21, 7, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(6, 8, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(21, 23, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(6, 23, 'hex')); - - // bottom-left anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-left', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(15, 31, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(0, 15, 'hex')); - - // bottom-left anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-left', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(10, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(9, 20, 'hex')); - - // bottom anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(8, 16, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 15, 'hex')); - - // bottom anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(23, 22, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(24, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(7, 6, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(8, 6, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 21, 'hex')); - $this->assertEquals('#0000ff', $img->pickColor(23, 6, 'hex')); - - // bottom-right anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-right', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(16, 16, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(15, 16, 'hex')); - - // bottom-right anchor coordinates - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'bottom-right', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(21, 21, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(22, 22, 'hex')); - - // center anchor - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'center', 0, 0); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex')); - - // center anchor coordinates / coordinates will be ignored for center - $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas - $img->insert($watermark, 'center', 10, 10); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals($img->getWidth(), 32); - $this->assertEquals($img->getHeight(), 32); - $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex')); - $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex')); - } - - public function testInsertWithAlphaChannel() - { - $img = $this->manager()->canvas(50, 50, 'ff0000'); - $img->insert('tests/images/circle.png'); - $this->assertColorAtPosition('#ff0000', $img, 0, 0); - $this->assertColorAtPosition('#330000', $img, 30, 30); - } - - public function testInsertAfterResize() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->resize(16, 16)->insert('tests/images/tile.png'); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#ffa601', $img, 8, 7); - } - - public function testInsertImagick() - { - $imagick = new \Imagick; - $imagick->readImage('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($imagick); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testInsertBinary() - { - $data = file_get_contents('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($data); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testInsertInterventionImage() - { - $obj = $this->manager()->make('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->insert($obj); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertColorAtPosition('#b4e000', $img, 0, 7); - $this->assertColorAtPosition('#00aef0', $img, 0, 8); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 24, 24); - } - - public function testOpacity() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->opacity(50); - $checkColor = $img->pickColor(7, 7, 'array'); - $this->assertEquals($checkColor[0], 180); - $this->assertEquals($checkColor[1], 224); - $this->assertEquals($checkColor[2], 0); - $this->assertEquals($checkColor[3], 0.5); - $checkColor = $img->pickColor(8, 8, 'array'); - $this->assertEquals($checkColor[0], 68); - $this->assertEquals($checkColor[1], 81); - $this->assertEquals($checkColor[2], 96); - $this->assertEquals($checkColor[3], 0.5); - $this->assertTransparentPosition($img, 0, 11); - } - - public function testMaskImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->mask('tests/images/gradient.png'); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 18, 18); - $this->assertTransparentPosition($img, 23, 23); - $this->assertTransparentPosition($img, 30, 30); - $alpha = $img->pickColor(23, 24, 'array'); - $this->assertLessThan(1, $alpha[3]); - $this->assertGreaterThanOrEqual(0, $alpha[3]); - $alpha = $img->pickColor(35, 25, 'array'); - $this->assertLessThan(1, $alpha[3]); - $this->assertGreaterThanOrEqual(0, $alpha[3]); - $alpha = $img->pickColor(25, 42, 'array'); - $this->assertLessThan(1, $alpha[3]); - $this->assertGreaterThanOrEqual(0, $alpha[3]); - } - - public function testMaskImageWithAlpha() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->mask('tests/images/star.png', true); - $this->assertTransparentPosition($img, 0, 0); - $this->assertTransparentPosition($img, 16, 16); - $this->assertTransparentPosition($img, 36, 36); - $this->assertTransparentPosition($img, 47, 47); - $alpha = $img->pickColor(18, 18, 'array'); - $this->assertLessThan(1, $alpha[3]); - $this->assertGreaterThanOrEqual(0, $alpha[3]); - $alpha = $img->pickColor(22, 35, 'array'); - $this->assertLessThan(1, $alpha[3]); - $this->assertGreaterThanOrEqual(0, $alpha[3]); - } - - public function testPixelateImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->pixelate(20); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testGreyscaleImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->greyscale(); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertTransparentPosition($img, 8, 0); - $this->assertColorAtPosition('#707070', $img, 0, 0); - } - - public function testInvertImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->invert(); - $this->assertInstanceOf('Intervention\Image\Image', $img); - $this->assertTransparentPosition($img, 8, 0); - $this->assertColorAtPosition('#4b1fff', $img, 0, 0); - } - - public function testBlurImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->blur(1); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testFillImageWithColor() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fill('b53717'); - $this->assertColorAtPosition('#b53717', $img, 0, 0); - $this->assertColorAtPosition('#b53717', $img, 15, 15); - } - - public function testFillImageWithColorAtPosition() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->fill('b53717', 0, 0); - $this->assertTransparentPosition($img, 0, 8); - $this->assertColorAtPosition('#b53717', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 15, 15); - } - - public function testFillImageWithImagick() - { - $imagick = new \Imagick; - $imagick->readImage('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($imagick, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testFillImageWithBinary() - { - $data = file_get_contents('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($data, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testFillImageWithInterventionImage() - { - $obj = $this->manager()->make('tests/images/tile.png'); - $img = $this->manager()->make('tests/images/trim.png'); - $img->fill($obj, 0, 0); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#00aef0', $img, 8, 7); - $this->assertColorAtPosition('#ffa601', $img, 20, 20); - } - - public function testPixelImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $coords = [[5, 5], [12, 12]]; - $img = $img->pixel('fdf5e4', $coords[0][0], $coords[0][1]); - $img = $img->pixel([255, 255, 255], $coords[1][0], $coords[1][1]); - $this->assertEquals('#fdf5e4', $img->pickColor($coords[0][0], $coords[0][1], 'hex')); - $this->assertEquals('#ffffff', $img->pickColor($coords[1][0], $coords[1][1], 'hex')); - } - - public function testRectangleImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->rectangle(5, 5, 11, 11, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('32ceca9759d1973dd461b39664df604d', $img->checksum()); - } - - public function testLineImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->line(0, 0, 15, 15, function ($draw) { $draw->color('#ff0000'); }); - $this->assertEquals('f5c585019bff361d91e2928b2ac2286b', $img->checksum()); - } - - public function testEllipseImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->ellipse(12, 8, 8, 8, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('9dc5bbec6d45868610c082a1d67640b5', $img->checksum()); - } - - public function testCircleImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $img->circle(12, 8, 8, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('a433c7c1a842ef83e1cb45875371358c', $img->checksum()); - } - - public function testPolygonImage() - { - $img = $this->manager()->canvas(16, 16, 'ffffff'); - $points = [3, 3, 11, 11, 7, 13]; - $img->polygon($points, function ($draw) { $draw->background('#ff0000'); $draw->border(1, '#0000ff'); }); - $this->assertEquals('e301afe179da858d441ad8fc0eb5490a', $img->checksum()); - } - - public function testResetImage() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->backup(); - $img->resize(30, 20); - $img->reset(); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - } - - public function testResetEmptyImage() - { - $img = $this->manager()->canvas(16, 16, '#0000ff'); - $img->backup(); - $img->resize(30, 20); - $img->fill('#ff0000'); - $img->reset(); - $this->assertInternalType('int', $img->getWidth()); - $this->assertInternalType('int', $img->getHeight()); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - $this->assertColorAtPosition('#0000ff', $img, 0, 0); - } - - public function testResetKeepTransparency() - { - $img = $this->manager()->make('tests/images/circle.png'); - $img->backup(); - $img->reset(); - $this->assertTransparentPosition($img, 0, 0); - } - - public function testResetToNamed() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->backup('original'); - $img->resize(30, 20); - $img->backup('30x20'); - - // reset to original - $img->reset('original'); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - - // reset to 30x20 - $img->reset('30x20'); - $this->assertEquals(30, $img->getWidth()); - $this->assertEquals(20, $img->getHeight()); - - // reset to original again - $img->reset('original'); - $this->assertEquals(16, $img->getWidth()); - $this->assertEquals(16, $img->getHeight()); - } - - public function testLimitColors() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->limitColors(4); - $this->assertLessThanOrEqual(5, $img->getCore()->getImageColors()); - } - - public function testLimitColorsKeepTransparency() - { - $img = $this->manager()->make('tests/images/star.png'); - $img->limitColors(16); - $this->assertLessThanOrEqual(17, $img->getCore()->getImageColors()); - $this->assertTransparentPosition($img, 0, 0); - $this->assertColorAtPosition('#680098', $img, 6, 12); - $this->assertColorAtPosition('#c2596a', $img, 22, 24); - } - - public function testLimitColorsKeepTransparencyWithMatte() - { - $img = $this->manager()->make('tests/images/star.png'); - $img->limitColors(32, '#00ff00'); - $this->assertLessThanOrEqual(33, $img->getCore()->getImageColors()); - $this->assertTransparentPosition($img, 0, 0); - $this->assertColorAtPosition('#00ff00', $img, 12, 10); - $this->assertColorAtPosition('#00ff00', $img, 22, 17); - $this->assertColorAtPosition('#e70012', $img, 16, 21); - } - - public function testLimitColorsNullWithMatte() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->limitColors(null, '#ff00ff'); - $this->assertColorAtPosition('#b4e000', $img, 0, 0); - $this->assertColorAtPosition('#445160', $img, 8, 8); - $this->assertColorAtPosition('#ff00ff', $img, 0, 8); - $this->assertColorAtPosition('#ff00ff', $img, 15, 0); - } - - public function testPickColorFromTrueColor() - { - $img = $this->manager()->make('tests/images/star.png'); - $c = $img->pickColor(0, 0); - $this->assertEquals(255, $c[0]); - $this->assertEquals(255, $c[1]); - $this->assertEquals(255, $c[2]); - $this->assertEquals(0, $c[3]); - - $c = $img->pickColor(11, 11); - $this->assertEquals(34, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(160, $c[2]); - $this->assertEquals(0.47, $c[3]); - - $c = $img->pickColor(16, 16); - $this->assertEquals(231, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(18, $c[2]); - $this->assertEquals(1, $c[3]); - } - - public function testPickColorFromIndexed() - { - $img = $this->manager()->make('tests/images/tile.png'); - $c = $img->pickColor(0, 0); - $this->assertEquals(180, $c[0]); - $this->assertEquals(224, $c[1]); - $this->assertEquals(0, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(8, 8); - $this->assertEquals(68, $c[0]); - $this->assertEquals(81, $c[1]); - $this->assertEquals(96, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(0, 15); - $this->assertEquals(0, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(0, $c[2]); - $this->assertEquals(0, $c[3]); - } - - public function testPickColorFromPalette() - { - $img = $this->manager()->make('tests/images/tile.png'); - $img->getCore()->quantizeImage(200, \Imagick::COLORSPACE_RGB, 0, false, false); - - $c = $img->pickColor(0, 0); - $this->assertEquals(180, $c[0]); - $this->assertEquals(224, $c[1]); - $this->assertEquals(0, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(8, 8); - $this->assertEquals(68, $c[0]); - $this->assertEquals(81, $c[1]); - $this->assertEquals(96, $c[2]); - $this->assertEquals(1, $c[3]); - - $c = $img->pickColor(0, 15); - $this->assertEquals(0, $c[0]); - $this->assertEquals(0, $c[1]); - $this->assertEquals(0, $c[2]); - $this->assertEquals(0, $c[3]); - } - - public function testInterlaceImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->interlace(); - $img->encode('png'); - $this->assertTrue((ord($img->encoded[28]) != '0')); - $img->interlace(false); - $img->encode('png'); - $this->assertFalse((ord($img->encoded[28]) != '0')); - } - - public function testGammaImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->gamma(1.6); - $this->assertColorAtPosition('#00c9f6', $img, 0, 0); - $this->assertColorAtPosition('#ffc308', $img, 24, 24); - } - - public function testBrightnessImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->brightness(35); - $this->assertColorAtPosition('#45ccff', $img, 0, 0); - $this->assertColorAtPosition('#ffc55b', $img, 24, 24); - } - - public function testContrastImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->contrast(35); - $this->assertColorAtPosition('#00feff', $img, 0, 0); - $this->assertColorAtPosition('#fffd04', $img, 24, 24); - } - - public function testColorizeImage() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->colorize(40, 25, -50); - $this->assertColorAtPosition('#00ece2', $img, 0, 0); - $this->assertColorAtPosition('#ffea00', $img, 24, 24); - } - - public function testTrimGradient() - { - $canvas = $this->manager()->make('tests/images/gradient.png'); - - $img = clone $canvas; - $img->trim(); - $this->assertEquals($img->getWidth(), 46); - $this->assertEquals($img->getHeight(), 46); - - $img = clone $canvas; - $img->trim(null, null, 10); - $this->assertEquals($img->getWidth(), 38); - $this->assertEquals($img->getHeight(), 38); - - $img = clone $canvas; - $img->trim(null, null, 20); - $this->assertEquals($img->getWidth(), 34); - $this->assertEquals($img->getHeight(), 34); - - $img = clone $canvas; - $img->trim(null, null, 30); - $this->assertEquals($img->getWidth(), 30); - $this->assertEquals($img->getHeight(), 30); - - $img = clone $canvas; - $img->trim(null, null, 40); - $this->assertEquals($img->getWidth(), 26); - $this->assertEquals($img->getHeight(), 26); - - $img = clone $canvas; - $img->trim(null, null, 50); - $this->assertEquals($img->getWidth(), 22); - $this->assertEquals($img->getHeight(), 22); - - $img = clone $canvas; - $img->trim(null, null, 60); - $this->assertEquals($img->getWidth(), 20); - $this->assertEquals($img->getHeight(), 20); - - $img = clone $canvas; - $img->trim(null, null, 70); - $this->assertEquals($img->getWidth(), 16); - $this->assertEquals($img->getHeight(), 16); - - $img = clone $canvas; - $img->trim(null, null, 80); - $this->assertEquals($img->getWidth(), 12); - $this->assertEquals($img->getHeight(), 12); - - $img = clone $canvas; - $img->trim(null, null, 90); - $this->assertEquals($img->getWidth(), 8); - $this->assertEquals($img->getHeight(), 8); - } - - public function testTrimOnlyLeftAndRight() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, ['left', 'right'], 60); - $this->assertEquals($img->getWidth(), 20); - $this->assertEquals($img->getHeight(), 50); - } - - public function testTrimOnlyTopAndBottom() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, ['top', 'bottom'], 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 20); - } - - public function testTrimOnlyTop() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, 'top', 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 35); - } - - public function testTrimOnlyBottom() - { - $img = $this->manager()->make('tests/images/gradient.png'); - $img->trim(null, 'top', 60); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 35); - } - - public function testTrimWithFeather() - { - $img = $this->manager()->make('tests/images/trim.png'); - $feather = 5; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - $img->destroy(); - - $img = $this->manager()->make('tests/images/trim.png'); - $feather = 10; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - $img->destroy(); - - $img = $this->manager()->make('tests/images/trim.png'); - $feather = 20; // must respect original dimensions of image - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 50); - $img->destroy(); - - $img = $this->manager()->make('tests/images/trim.png'); - $feather = -5; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - $img->destroy(); - - $img = $this->manager()->make('tests/images/trim.png'); - $feather = -10; - $img->trim(null, null, null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - $img->destroy(); - - // trim only left and right with feather - $img = $this->manager()->make('tests/images/trim.png'); - $feather = 10; - $img->trim(null, ['left', 'right'], null, $feather); - $this->assertEquals($img->getWidth(), 28 + $feather * 2); - $this->assertEquals($img->getHeight(), 50); - $img->destroy(); - - // trim only top and bottom with feather - $img = $this->manager()->make('tests/images/trim.png'); - $feather = 10; - $img->trim(null, ['top', 'bottom'], null, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 28 + $feather * 2); - $img->destroy(); - - // trim with tolerance and feather - $img = $this->manager()->make('tests/images/gradient.png'); - $feather = 2; - $img->trim(null, null, 10, $feather); - $this->assertEquals($img->getWidth(), 38 + $feather * 2); - $this->assertEquals($img->getHeight(), 38 + $feather * 2); - $img->destroy(); - - $img = $this->manager()->make('tests/images/gradient.png'); - $feather = 5; - $img->trim(null, null, 10, $feather); - $this->assertEquals($img->getWidth(), 38 + $feather * 2); - $this->assertEquals($img->getHeight(), 38 + $feather * 2); - $img->destroy(); - - $img = $this->manager()->make('tests/images/gradient.png'); - $feather = 10; // should respect original dimensions - $img->trim(null, null, 20, $feather); - $this->assertEquals($img->getWidth(), 50); - $this->assertEquals($img->getHeight(), 50); - $img->destroy(); - } - - public function testEncodeDefault() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode(); - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $img->encoded); - $this->assertEquals('image/png', $mime); - } - - public function testEncodeJpeg() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('jpg'); - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $img->encoded); - $this->assertEquals('image/jpeg', $mime); - } - - public function testEncodeGif() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('gif'); - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $img->encoded); - $this->assertEquals('image/gif', $mime); - } - - public function testEncodeDataUrl() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->encode('data-url'); - $this->assertEquals('data:image/png;base64', substr($img->encoded, 0, 21)); - } - - public function testExifReadAll() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif(); - $this->assertInternalType('array', $data); - $this->assertGreaterThanOrEqual(13, count($data)); - } - - public function testExifReadKey() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif('Artist'); - $this->assertInternalType('string', $data); - $this->assertEquals('Oliver Vogel', $data); - } - - public function testExifReadNotExistingKey() - { - $img = $this->manager()->make('tests/images/exif.jpg'); - $data = $img->exif('xxx'); - $this->assertEquals(null, $data); - } - - public function testSaveImage() - { - $save_as = 'tests/tmp/foo.jpg'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as, 80); - $this->assertFileExists($save_as); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.jpg'); - $this->assertEquals($img->extension, 'jpg'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/jpeg'); - @unlink($save_as); - - $save_as = 'tests/tmp/foo.png'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.png'); - $this->assertEquals($img->extension, 'png'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/png'); - $this->assertFileExists($save_as); - @unlink($save_as); - - $save_as = 'tests/tmp/foo.jpg'; - $img = $this->manager()->make('tests/images/trim.png'); - $img->save($save_as, 0); - $this->assertEquals($img->dirname, 'tests/tmp'); - $this->assertEquals($img->basename, 'foo.jpg'); - $this->assertEquals($img->extension, 'jpg'); - $this->assertEquals($img->filename, 'foo'); - $this->assertEquals($img->mime, 'image/jpeg'); - $this->assertFileExists($save_as); - @unlink($save_as); - } - - public function testSaveImageWithoutParameter() - { - $path = 'tests/tmp/bar.png'; - - // create temp. test image (red) - $img = $this->manager()->canvas(16, 16, '#ff0000'); - $img->save($path); - $img->destroy(); - - // open test image again - $img = $this->manager()->make($path); - $this->assertColorAtPosition('#ff0000', $img, 0, 0); - - // fill with green and save wthout paramater - $img->fill('#00ff00'); - $img->save(); - $img->destroy(); - - // re-open test image (should be green) - $img = $this->manager()->make($path); - $this->assertColorAtPosition('#00ff00', $img, 0, 0); - $img->destroy(); - - @unlink($path); - } - - /** - * @expectedException ImagickException - */ - public function testDestroy() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->destroy(); - $img->getCore()->getImageWidth(); // try to get width (should throw exception) - } - - /** - * @expectedException Exception - */ - public function testDestroyWithBackup() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->backup(); - $img->destroy(); - $img->getBackup()->getImageWidth(); // try to get width (should throw exception) - } - - public function testStringConversion() - { - $img = $this->manager()->make('tests/images/trim.png'); - $value = strval($img); - $this->assertInternalType('string', $value); - } - - public function testFilter() - { - $img = $this->manager()->make('tests/images/trim.png'); - $img->filter(new \Intervention\Image\Filters\DemoFilter(10)); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - public function testCloneImageObject() - { - $img = $this->manager()->make('tests/images/trim.png'); - $cln = clone $img; - - // destroy original - $img->destroy(); - unset($img); - - // clone should be still intact - $this->assertInstanceOf('Intervention\Image\Image', $cln); - $this->assertInstanceOf('Imagick', $cln->getCore()); - } - - public function testGifConversionKeepsTransparency() - { - $save_as = 'tests/tmp/foo.gif'; - - // create gif image from transparent png - $img = $this->manager()->make('tests/images/star.png'); - $img->save($save_as); - - // new gif image should be transparent - $img = $this->manager()->make($save_as); - $this->assertTransparentPosition($img, 0, 0); - @unlink($save_as); - } - - private function assertColorAtPosition($color, $img, $x, $y) - { - $pick = $img->pickColor($x, $y, 'hex'); - $this->assertEquals($color, $pick); - $this->assertInstanceOf('Intervention\Image\Image', $img); - } - - private function assertTransparentPosition($img, $x, $y, $transparent = 0) - { - // background should be transparent - $color = $img->pickColor($x, $y, 'array'); - $this->assertEquals($transparent, $color[3]); // alpha channel - } - - private function manager() - { - return new \Intervention\Image\ImageManager([ - 'driver' => 'imagick' - ]); - } -} diff --git a/tests/InsertCommandTest.php b/tests/InsertCommandTest.php deleted file mode 100644 index fa0b521c..00000000 --- a/tests/InsertCommandTest.php +++ /dev/null @@ -1,67 +0,0 @@ -shouldReceive('align')->with('center', 10, 20)->once()->andReturn($image_size); - $watermark_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $watermark_size->shouldReceive('align')->with('center')->once()->andReturn($watermark_size); - $image_size->shouldReceive('relativePosition')->with($watermark_size)->once()->andReturn($position); - - $path = __DIR__.'/images/test.jpg'; - $resource = imagecreatefromjpeg($path); - $watermark = Mockery::mock('Intervention\Image\Image'); - $driver = Mockery::mock('Intervention\Image\Gd\Driver'); - $driver->shouldReceive('init')->with($path)->once()->andReturn($watermark); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->times(2)->andReturn($resource); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $watermark->shouldReceive('getSize')->once()->andReturn($watermark_size); - $watermark->shouldReceive('getCore')->once()->andReturn($resource); - - $command = new InsertGd([$path, 'center', 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $position = Mockery::mock('\Intervention\Image\Point', [10, 20]); - - $image_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $image_size->shouldReceive('align')->with('center', 10, 20)->once()->andReturn($image_size); - $watermark_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $watermark_size->shouldReceive('align')->with('center')->once()->andReturn($watermark_size); - $image_size->shouldReceive('relativePosition')->with($watermark_size)->once()->andReturn($position); - - $path = __DIR__.'/images/test.jpg'; - $watermark = Mockery::mock('Intervention\Image\Image'); - $driver = Mockery::mock('Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('init')->with($path)->once()->andReturn($watermark); - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('compositeimage')->with($imagick, \Imagick::COMPOSITE_DEFAULT, 10, 20)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $watermark->shouldReceive('getSize')->once()->andReturn($watermark_size); - $watermark->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new InsertImagick([$path, 'center', 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/InterlaceCommandTest.php b/tests/InterlaceCommandTest.php deleted file mode 100644 index 907bc2cb..00000000 --- a/tests/InterlaceCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new InterlaceGd([true]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('setinterlacescheme')->with(\Imagick::INTERLACE_LINE)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new InterlaceImagick([true]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/InvertCommandTest.php b/tests/InvertCommandTest.php deleted file mode 100644 index 3cad4dda..00000000 --- a/tests/InvertCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new InvertGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('negateimage')->with(false)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new InvertImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/IptcCommandTest.php b/tests/IptcCommandTest.php deleted file mode 100644 index 27c1ef34..00000000 --- a/tests/IptcCommandTest.php +++ /dev/null @@ -1,72 +0,0 @@ -dirname = __DIR__.'/images'; - $image->basename = 'iptc.jpg'; - $command = new IptcCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - } - - public function testFetchDefined() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new IptcCommand(['AuthorByline']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals('Oliver Vogel', $command->getOutput()); - } - - - public function testFetchNonExisting() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->dirname = __DIR__.'/images'; - $image->basename = 'exif.jpg'; - $command = new IptcCommand(['xxx']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } - - - public function testFetchFromPng() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->dirname = __DIR__.'/images'; - $image->basename = 'star.png'; - $command = new IptcCommand(['Orientation']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } - - public function testReturnNullOnIptcReadFail() - { - $image = Mockery::mock('Intervention\Image\Image'); - $command = new IptcCommand(['Orientation']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertEquals(null, $command->getOutput()); - } -} diff --git a/tests/LimitColorsCommandTest.php b/tests/LimitColorsCommandTest.php deleted file mode 100644 index e76d57a4..00000000 --- a/tests/LimitColorsCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $image->shouldReceive('getSize')->once()->andReturn($size); - $command = new LimitColorsGd([16]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $size = Mockery::mock('\Intervention\Image\Size', [32, 32]); - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('separateimagechannel')->with(\Imagick::CHANNEL_ALPHA)->times(2); - $imagick->shouldReceive('transparentpaintimage')->with('#ffffff', 0, 0, false)->once(); - $imagick->shouldReceive('negateimage')->with(false)->once(); - $imagick->shouldReceive('quantizeimage')->with(16, \Imagick::COLORSPACE_RGB, 0, false, false)->once(); - $imagick->shouldReceive('compositeimage')->once(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('getCore')->times(3)->andReturn($imagick); - $command = new LimitColorsImagick([16]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/LineCommandTest.php b/tests/LineCommandTest.php deleted file mode 100644 index 2dadb2a0..00000000 --- a/tests/LineCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new LineCommand([10, 15, 100, 150]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('drawimage'); - $driver = Mockery::mock('\Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('getDriverName')->once()->andReturn('Imagick'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - - $command = new LineCommand([10, 15, 100, 150]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - -} diff --git a/tests/LineShapeTest.php b/tests/LineShapeTest.php deleted file mode 100644 index b95f71bf..00000000 --- a/tests/LineShapeTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertInstanceOf('Intervention\Image\Gd\Shapes\LineShape', $line); - $this->assertEquals(10, $line->x); - $this->assertEquals(15, $line->y); - - // imagick - $line = new LineImagick(10, 15); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\LineShape', $line); - $this->assertEquals(10, $line->x); - $this->assertEquals(15, $line->y); - } - - public function testApplyToImage() - { - // gd - $core = imagecreatetruecolor(300, 200); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $line = new LineGd(10, 15); - $result = $line->applyToImage($image, 100, 200); - $this->assertInstanceOf('Intervention\Image\Gd\Shapes\LineShape', $line); - $this->assertTrue($result); - - // imagick - $core = Mockery::mock('\Imagick'); - $core->shouldReceive('drawimage')->once(); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $line = new LineImagick(10, 15); - $result = $line->applyToImage($image, 100, 200); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\LineShape', $line); - $this->assertTrue($result); - } -} diff --git a/tests/MaskCommandTest.php b/tests/MaskCommandTest.php deleted file mode 100644 index 6330670a..00000000 --- a/tests/MaskCommandTest.php +++ /dev/null @@ -1,68 +0,0 @@ -shouldReceive('getSize')->once()->andReturn($mask_size); - $mask_image->shouldReceive('pickColor')->andReturn([0,0,0,0]); - - $canvas_image = Mockery::mock('Intervention\Image\Image'); - $canvas_core = imagecreatetruecolor(32, 32); - $canvas_image->shouldReceive('getCore')->times(2)->andReturn($canvas_core); - $canvas_image->shouldReceive('pixel'); - - $driver = Mockery::mock('Intervention\Image\Gd\Driver'); - $driver->shouldReceive('newImage')->with(32, 32, [0,0,0,0])->once()->andReturn($canvas_image); - $driver->shouldReceive('init')->with($mask_path)->once()->andReturn($mask_image); - - $image_size = Mockery::mock('Intervention\Image\Size', [32, 32]); - $image_core = imagecreatefrompng(__DIR__.'/images/trim.png'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $image->shouldReceive('getDriver')->times(2)->andReturn($driver); - $image->shouldReceive('pickColor')->andReturn([0,0,0,0]); - $image->shouldReceive('setCore')->with($canvas_core)->once(); - - $command = new MaskGd([$mask_path, true]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $mask_core = Mockery::mock('Imagick'); - $mask_path = __DIR__.'images/star.png'; - $mask_image = Mockery::mock('Intervention\Image\Image'); - $mask_image->shouldReceive('getCore')->once()->andReturn($mask_core); - $mask_size = Mockery::mock('Intervention\Image\Size', [32, 32]); - $mask_image->shouldReceive('getSize')->once()->andReturn($mask_size); - - $driver = Mockery::mock('Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('init')->with($mask_path)->once()->andReturn($mask_image); - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('setimagematte')->with(true)->once(); - $imagick->shouldReceive('compositeimage')->with($mask_core, \Imagick::COMPOSITE_DSTIN, 0, 0)->once(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image_size = Mockery::mock('Intervention\Image\Size', [32, 32]); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - - $command = new MaskImagick([$mask_path, true]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/OpacityCommandTest.php b/tests/OpacityCommandTest.php deleted file mode 100644 index aac04971..00000000 --- a/tests/OpacityCommandTest.php +++ /dev/null @@ -1,44 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($mask_core); - - $resource = imagecreatefrompng(__DIR__.'/images/trim.png'); - $driver = Mockery::mock('\Intervention\Image\Gd\Driver'); - $driver->shouldReceive('newImage')->with(32, 32, 'rgba(0, 0, 0, 0.5)')->andReturn($mask); - - $size = Mockery::mock('\Intervention\Image\Size', [32, 32]); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('mask')->with($mask_core, true)->once(); - $command = new OpacityGd([50]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('evaluateimage')->with(\Imagick::EVALUATE_DIVIDE, 2, \Imagick::CHANNEL_ALPHA)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new OpacityImagick([50]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/OrientateCommandTest.php b/tests/OrientateCommandTest.php deleted file mode 100644 index 884fcbb1..00000000 --- a/tests/OrientateCommandTest.php +++ /dev/null @@ -1,94 +0,0 @@ -shouldReceive('exif')->with('Orientation')->once()->andReturn(2); - $image->shouldReceive('flip')->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationThree() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(3); - $image->shouldReceive('rotate')->with(180)->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationFour() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(4); - $image->shouldReceive('rotate')->with(180)->once()->andReturn($image); - $image->shouldReceive('flip')->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationFive() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(5); - $image->shouldReceive('rotate')->with(270)->once()->andReturn($image); - $image->shouldReceive('flip')->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationSix() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(6); - $image->shouldReceive('rotate')->with(270)->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationSeven() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(7); - $image->shouldReceive('rotate')->with(90)->once()->andReturn($image); - $image->shouldReceive('flip')->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationEight() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(8); - $image->shouldReceive('rotate')->with(90)->once(); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testExecuteOrientationNoExifData() - { - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('exif')->with('Orientation')->once()->andReturn(null); - $command = new OrientateCommand([]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/PickColorCommandTest.php b/tests/PickColorCommandTest.php deleted file mode 100644 index fecc676f..00000000 --- a/tests/PickColorCommandTest.php +++ /dev/null @@ -1,67 +0,0 @@ -shouldReceive('getCore')->times(2)->andReturn($resource); - $command = new PickColorGd([1, 2]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - $this->assertEquals(4, count($command->getOutput())); - } - - public function testGdWithFormat() - { - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->times(2)->andReturn($resource); - $command = new PickColorGd([1, 2, 'hex']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('string', $command->getOutput()); - $this->assertEquals('#ffffff', $command->getOutput()); - } - - public function testImagickWithCoordinates() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getimagepixelcolor')->with(1, 2)->andReturn(new ImagickPixel); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new PickColorImagick([1, 2]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('array', $command->getOutput()); - $this->assertEquals(4, count($command->getOutput())); - } - - public function testImagickWithFormat() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('getimagepixelcolor')->with(1, 2)->andReturn(new ImagickPixel('#ff0000')); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new PickColorImagick([1, 2, 'hex']); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - $this->assertInternalType('string', $command->getOutput()); - $this->assertEquals('#ff0000', $command->getOutput()); - } -} diff --git a/tests/PixelCommandTest.php b/tests/PixelCommandTest.php deleted file mode 100644 index ad1681d7..00000000 --- a/tests/PixelCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new PixelGd(['#b53717', 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('drawimage')->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new PixelImagick(['#b53717', 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/PixelateCommandTest.php b/tests/PixelateCommandTest.php deleted file mode 100644 index 29eba75f..00000000 --- a/tests/PixelateCommandTest.php +++ /dev/null @@ -1,37 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new PixelateGd([10]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('scaleimage')->with(80, 60)->once()->andReturn(true); - $imagick->shouldReceive('scaleimage')->with(800, 600)->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->times(2)->andReturn($imagick); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $command = new PixelateImagick([10]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/PointTest.php b/tests/PointTest.php deleted file mode 100644 index 816c1b13..00000000 --- a/tests/PointTest.php +++ /dev/null @@ -1,47 +0,0 @@ -assertInstanceOf('Intervention\Image\Point', $point); - $this->assertEquals(0, $point->x); - $this->assertEquals(0, $point->y); - } - - public function testConstructorWithParameters() - { - $point = new Point(40, 50); - $this->assertInstanceOf('Intervention\Image\Point', $point); - $this->assertEquals(40, $point->x); - $this->assertEquals(50, $point->y); - } - - public function testSetX() - { - $point = new Point(0, 0); - $point->setX(100); - $this->assertEquals(100, $point->x); - $this->assertEquals(0, $point->y); - } - - public function testSetY() - { - $point = new Point(0, 0); - $point->setY(100); - $this->assertEquals(0, $point->x); - $this->assertEquals(100, $point->y); - } - - public function testSetPosition() - { - $point = new Point(0, 0); - $point->setPosition(100, 200); - $this->assertEquals(100, $point->x); - $this->assertEquals(200, $point->y); - } -} diff --git a/tests/PolygonCommandTest.php b/tests/PolygonCommandTest.php deleted file mode 100644 index 1580d8bc..00000000 --- a/tests/PolygonCommandTest.php +++ /dev/null @@ -1,45 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new PolygonCommand([$points]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - $points = [1, 2, 3, 4, 5, 6]; - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('drawimage'); - $driver = Mockery::mock('\Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('getDriverName')->once()->andReturn('Imagick'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - - $command = new PolygonCommand([$points]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - -} diff --git a/tests/PolygonShapeTest.php b/tests/PolygonShapeTest.php deleted file mode 100644 index be0001c4..00000000 --- a/tests/PolygonShapeTest.php +++ /dev/null @@ -1,57 +0,0 @@ -assertInstanceOf('Intervention\Image\Gd\Shapes\PolygonShape', $polygon); - $this->assertEquals([1, 2, 3, 4, 5, 6], $polygon->points); - - } - - public function testGdApplyToImage() - { - $core = imagecreatetruecolor(300, 200); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $polygon = new PolygonGd([1, 2, 3, 4, 5, 6]); - $result = $polygon->applyToImage($image); - $this->assertInstanceOf('Intervention\Image\Gd\Shapes\PolygonShape', $polygon); - $this->assertTrue($result); - } - - public function testImagickConstructor() - { - $polygon = new PolygonImagick([1, 2, 3, 4, 5, 6]); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\PolygonShape', $polygon); - $this->assertEquals([ - ['x' => 1, 'y' => 2], - ['x' => 3, 'y' => 4], - ['x' => 5, 'y' => 6]], - $polygon->points); - - } - - public function testImagickApplyToImage() - { - $core = Mockery::mock('\Imagick'); - $core->shouldReceive('drawimage')->once(); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $polygon = new PolygonImagick([1, 2, 3, 4, 5, 6]); - $result = $polygon->applyToImage($image); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\PolygonShape', $polygon); - $this->assertTrue($result); - } - -} diff --git a/tests/PsrResponseCommandTest.php b/tests/PsrResponseCommandTest.php deleted file mode 100644 index f7753f04..00000000 --- a/tests/PsrResponseCommandTest.php +++ /dev/null @@ -1,58 +0,0 @@ -'; - - $image = Mockery::mock('Intervention\Image\Image'); - $stream = \GuzzleHttp\Psr7\stream_for($encodedContent); - - $image->shouldReceive('stream') - ->with('jpg', 87) - ->once() - ->andReturn($stream); - - $image->shouldReceive('getEncoded') - ->twice() - ->andReturn($encodedContent); - - $command = new PsrResponseCommand(['jpg', 87]); - $result = $command->execute($image); - - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - - $output = $command->getOutput(); - - $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $output); - - /** - * @var \Psr\Http\Message\ResponseInterface $output - */ - $this->assertEquals($stream, $output->getBody()); - $this->assertEquals($encodedContent, (string)$output->getBody()); - - $this->assertTrue($output->hasHeader('Content-Type')); - $this->assertTrue($output->hasHeader('Content-Length')); - - $this->assertTrue(in_array($output->getHeaderLine('Content-Type'), [ - 'application/xml', - 'text/xml', - ])); - - $this->assertEquals( - strlen($encodedContent), - $output->getHeaderLine('Content-Length') - ); - } -} diff --git a/tests/RectangleCommandTest.php b/tests/RectangleCommandTest.php deleted file mode 100644 index 3def6859..00000000 --- a/tests/RectangleCommandTest.php +++ /dev/null @@ -1,43 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new RectangleCommand([10, 15, 100, 150]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - $imagick = Mockery::mock('\Imagick'); - $imagick->shouldReceive('drawimage'); - $driver = Mockery::mock('\Intervention\Image\Imagick\Driver'); - $driver->shouldReceive('getDriverName')->once()->andReturn('Imagick'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - - $command = new RectangleCommand([10, 15, 100, 150]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - -} diff --git a/tests/RectangleShapeTest.php b/tests/RectangleShapeTest.php deleted file mode 100644 index d4d7b2a0..00000000 --- a/tests/RectangleShapeTest.php +++ /dev/null @@ -1,54 +0,0 @@ -assertInstanceOf('Intervention\Image\Gd\Shapes\RectangleShape', $rectangle); - $this->assertEquals(10, $rectangle->x1); - $this->assertEquals(15, $rectangle->y1); - $this->assertEquals(100, $rectangle->x2); - $this->assertEquals(150, $rectangle->y2); - - // imagick - $rectangle = new RectangleImagick(10, 15, 100, 150); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\RectangleShape', $rectangle); - $this->assertEquals(10, $rectangle->x1); - $this->assertEquals(15, $rectangle->y1); - $this->assertEquals(100, $rectangle->x2); - $this->assertEquals(150, $rectangle->y2); - } - - public function testApplyToImage() - { - // gd - $core = imagecreatetruecolor(300, 200); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $rectangle = new RectangleGd(10, 15, 100, 150); - $result = $rectangle->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Gd\Shapes\RectangleShape', $rectangle); - $this->assertTrue($result); - - // imagick - $core = Mockery::mock('\Imagick'); - $core->shouldReceive('drawimage')->once(); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($core); - $rectangle = new RectangleImagick(10, 15, 100, 150); - $result = $rectangle->applyToImage($image, 10, 20); - $this->assertInstanceOf('Intervention\Image\Imagick\Shapes\RectangleShape', $rectangle); - $this->assertTrue($result); - } -} diff --git a/tests/ResetCommandTest.php b/tests/ResetCommandTest.php deleted file mode 100644 index 29a545a2..00000000 --- a/tests/ResetCommandTest.php +++ /dev/null @@ -1,71 +0,0 @@ -shouldReceive('cloneCore')->with($resource)->once()->andReturn($resource); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('setCore')->once(); - $image->shouldReceive('getBackup')->once()->andReturn($resource); - $command = new ResetGd([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testGdWithName() - { - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $driver = Mockery::mock('Intervention\Image\Gd\Driver'); - $driver->shouldReceive('cloneCore')->with($resource)->once()->andReturn($resource); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $image->shouldReceive('getBackup')->once()->withArgs(['fooBackup'])->andReturn($resource); - $command = new ResetGd(['fooBackup']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickWithoutName() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('clear')->once(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('setCore')->once(); - $image->shouldReceive('getBackup')->once()->andReturn($imagick); - $command = new ResetImagick([]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickWithName() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('clear')->once(); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('setCore')->once(); - $image->shouldReceive('getBackup')->once()->withArgs(['fooBackup'])->andReturn($imagick); - $command = new ResetImagick(['fooBackup']); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/ResizeCanvasCommandTest.php b/tests/ResizeCanvasCommandTest.php deleted file mode 100644 index fb6480a1..00000000 --- a/tests/ResizeCanvasCommandTest.php +++ /dev/null @@ -1,80 +0,0 @@ -shouldReceive('align')->with('center')->andReturn($canvas_size); - $canvas_size->shouldReceive('relativePosition')->andReturn($canvas_pos); - $image_pos = Mockery::mock('\Intervention\Image\Point', [0, 0]); - $image_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $image_size->shouldReceive('align')->with('center')->andReturn($image_size); - $image_size->shouldReceive('relativePosition')->andReturn($image_pos); - $canvas = Mockery::mock('\Intervention\Image\Image'); - $canvas->shouldReceive('getCore')->times(5)->andReturn($resource); - $canvas->shouldReceive('getSize')->andReturn($canvas_size); - $driver = Mockery::mock('\Intervention\Image\Gd\Driver'); - $driver->shouldReceive('newImage')->with(820, 640, '#b53717')->once()->andReturn($canvas); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new ResizeCanvasGd([20, 40, 'center', true, '#b53717']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $canvas_pos = Mockery::mock('\Intervention\Image\Point', [0, 0]); - $canvas_size = Mockery::mock('\Intervention\Image\Size', [820, 640]); - $canvas_size->shouldReceive('align')->with('center')->andReturn($canvas_size); - $canvas_size->shouldReceive('relativePosition')->andReturn($canvas_pos); - $image_pos = Mockery::mock('\Intervention\Image\Point', [0, 0]); - $image_size = Mockery::mock('\Intervention\Image\Size', [800, 600]); - $image_size->shouldReceive('align')->with('center')->andReturn($image_size); - $image_size->shouldReceive('relativePosition')->andReturn($image_pos); - $canvas = Mockery::mock('\Intervention\Image\Image'); - - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('cropimage')->with(800, 600, 0, 0)->once(); - $imagick->shouldReceive('compositeimage')->with($imagick, 40, 0, 0)->once(); - $imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->once(); - $imagick->shouldReceive('drawimage')->once(); - $imagick->shouldReceive('transparentpaintimage')->once(); - $imagick->shouldReceive('getimagecolorspace')->once(); - $imagick->shouldReceive('setimagecolorspace')->once(); - - $canvas->shouldReceive('getCore')->times(6)->andReturn($imagick); - $canvas->shouldReceive('getSize')->andReturn($canvas_size); - $canvas->shouldReceive('pickColor')->with(0, 0, 'hex')->once()->andReturn('#000000'); - $driver = Mockery::mock('\Intervention\Image\Gd\Driver'); - $driver->shouldReceive('newImage')->with(820, 640, '#b53717')->once()->andReturn($canvas); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getSize')->once()->andReturn($image_size); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getCore')->times(3)->andReturn($imagick); - $image->shouldReceive('setCore')->once(); - $command = new ResizeCanvasImagick([20, 40, 'center', true, '#b53717']); - $result = $command->execute($image); - $this->assertTrue($result); - } - -} diff --git a/tests/ResizeCommandTest.php b/tests/ResizeCommandTest.php deleted file mode 100644 index 130ea4b2..00000000 --- a/tests/ResizeCommandTest.php +++ /dev/null @@ -1,49 +0,0 @@ -upsize(); }; - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->with(300, 200, $callback)->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(800); - $size->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new ResizeCommandGd([300, 200, $callback]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $callback = function ($constraint) { $constraint->upsize(); }; - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('scaleimage')->with(300, 200)->once()->andReturn(true); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->with(300, 200, $callback)->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(300); - $size->shouldReceive('getHeight')->once()->andReturn(200); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('getSize')->once()->andReturn($size); - $command = new ResizeCommandImagick([300, 200, $callback]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php deleted file mode 100644 index 6a10b2c6..00000000 --- a/tests/ResponseTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertInstanceOf('\Intervention\Image\Response', $response); - $this->assertInstanceOf('\Intervention\Image\Image', $response->image); - } - - public function testConstructorWithParameters() - { - $image = Mockery::mock('\Intervention\Image\Image'); - $response = new Response($image, 'jpg', 75); - $this->assertInstanceOf('\Intervention\Image\Response', $response); - $this->assertInstanceOf('\Intervention\Image\Image', $response->image); - $this->assertEquals('jpg', $response->format); - $this->assertEquals(75, $response->quality); - } -} diff --git a/tests/RotateCommandTest.php b/tests/RotateCommandTest.php deleted file mode 100644 index 48facd16..00000000 --- a/tests/RotateCommandTest.php +++ /dev/null @@ -1,48 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once()->andReturn($resource); - $command = new RotateGd([45, '#b53717']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $pixel = Mockery::mock('ImagickPixel', ['#b53717']); - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('rotateimage')->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new RotateImagick([45, '#b53717']); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagickWithLargeRotation() - { - $rotation = 45; - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('rotateimage')->with(Mockery::type('object'), -$rotation)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new RotateImagick([$rotation + (360 * 1000), '#b53717']); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/SharpenCommandTest.php b/tests/SharpenCommandTest.php deleted file mode 100644 index ed187d87..00000000 --- a/tests/SharpenCommandTest.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldReceive('getCore')->once()->andReturn($resource); - $command = new SharpenGd([50]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('unsharpmaskimage')->with(1, 1, 8, 0)->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $command = new SharpenImagick([50]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/SizeTest.php b/tests/SizeTest.php deleted file mode 100644 index 35ced232..00000000 --- a/tests/SizeTest.php +++ /dev/null @@ -1,436 +0,0 @@ -assertInstanceOf('Intervention\Image\Size', $size); - $this->assertInstanceOf('Intervention\Image\Point', $size->pivot); - $this->assertEquals(1, $size->width); - $this->assertEquals(1, $size->height); - } - - public function testConstructorWithCoordinates() - { - $pivot = Mockery::mock('Intervention\Image\Point'); - $size = new Size(300, 200, $pivot); - $this->assertInstanceOf('Intervention\Image\Size', $size); - $this->assertInstanceOf('Intervention\Image\Point', $size->pivot); - $this->assertEquals(300, $size->width); - $this->assertEquals(200, $size->height); - } - - public function testGetWidth() - { - $size = new Size(800, 600); - $this->assertEquals(800, $size->getWidth()); - } - - public function testGetHeight() - { - $size = new Size(800, 600); - $this->assertEquals(600, $size->getHeight()); - } - - public function testGetRatio() - { - $size = new Size(800, 600); - $this->assertEquals(1.33333333333, $size->getRatio()); - - $size = new Size(100, 100); - $this->assertEquals(1, $size->getRatio()); - - $size = new Size(1920, 1080); - $this->assertEquals(1.777777777778, $size->getRatio()); - } - - public function testResize() - { - $size = new Size(800, 600); - $size->resize(1000, 2000); - $this->assertEquals(1000, $size->width); - $this->assertEquals(2000, $size->height); - - $size = new Size(800, 600); - $size->resize(2000, null); - $this->assertEquals(2000, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 1000); - $this->assertEquals(800, $size->width); - $this->assertEquals(1000, $size->height); - } - - public function testResizeWithCallbackAspectRatio() - { - $size = new Size(800, 600); - $size->resize(1000, 2000, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(1000, $size->width); - $this->assertEquals(750, $size->height); - - $size = new Size(800, 600); - $size->resize(2000, 1000, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(1333, $size->width); - $this->assertEquals(1000, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 3000, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(4000, $size->width); - $this->assertEquals(3000, $size->height); - - $size = new Size(800, 600); - $size->resize(8000, null, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(8000, $size->width); - $this->assertEquals(6000, $size->height); - - $size = new Size(800, 600); - $size->resize(100, 400, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(100, $size->width); - $this->assertEquals(75, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 100, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(133, $size->width); - $this->assertEquals(100, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 300, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(80, null, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(80, $size->width); - $this->assertEquals(60, $size->height); - - $size = new Size(640, 480); - $size->resize(225, null, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(225, $size->width); - $this->assertEquals(169, $size->height); - - $size = new Size(640, 480); - $size->resize(223, null, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(223, $size->width); - $this->assertEquals(167, $size->height); - - $size = new Size(600, 800); - $size->resize(300, 300, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(225, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 10, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(13, $size->width); - $this->assertEquals(10, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, 1200, function ($c) { $c->aspectRatio(); }); - $this->assertEquals(1000, $size->width); - $this->assertEquals(750, $size->height); - } - - public function testResizeWithCallbackUpsize() - { - $size = new Size(800, 600); - $size->resize(1000, 2000, function ($c) { $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 1000, function ($c) { $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, 400, function ($c) { $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(400, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 300, function ($c) { $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, null, function ($c) { $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 1000, function ($c) { $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - } - - public function testResizeWithCallbackAspectRatioAndUpsize() - { - $size = new Size(800, 600); - $size->resize(1000, 2000, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, 600, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, 300, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 1000, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(400, null, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 300, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(400, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(1000, null, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(null, 1000, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(800, $size->width); - $this->assertEquals(600, $size->height); - - $size = new Size(800, 600); - $size->resize(100, 100, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(100, $size->width); - $this->assertEquals(75, $size->height); - - $size = new Size(800, 600); - $size->resize(300, 200, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(267, $size->width); - $this->assertEquals(200, $size->height); - - $size = new Size(600, 800); - $size->resize(300, 300, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(225, $size->width); - $this->assertEquals(300, $size->height); - - $size = new Size(800, 600); - $size->resize(400, 10, function ($c) { $c->aspectRatio(); $c->upsize(); }); - $this->assertEquals(13, $size->width); - $this->assertEquals(10, $size->height); - } - - public function testRelativePosition() - { - $container = new Size(800, 600); - $input = new Size(200, 100); - $container->align('top-left'); - $input->align('top-left'); - $pos = $container->relativePosition($input); - $this->assertEquals(0, $pos->x); - $this->assertEquals(0, $pos->y); - - $container = new Size(800, 600); - $input = new Size(200, 100); - $container->align('center'); - $input->align('top-left'); - $pos = $container->relativePosition($input); - $this->assertEquals(400, $pos->x); - $this->assertEquals(300, $pos->y); - - $container = new Size(800, 600); - $input = new Size(200, 100); - $container->align('bottom-right'); - $input->align('top-right'); - $pos = $container->relativePosition($input); - $this->assertEquals(600, $pos->x); - $this->assertEquals(600, $pos->y); - - $container = new Size(800, 600); - $input = new Size(200, 100); - $container->align('center'); - $input->align('center'); - $pos = $container->relativePosition($input); - $this->assertEquals(300, $pos->x); - $this->assertEquals(250, $pos->y); - } - - public function testAlign() - { - $width = 640; - $height = 480; - $pivot = Mockery::mock('Intervention\Image\Point'); - $pivot->shouldReceive('setPosition')->with(0, 0)->once(); - $pivot->shouldReceive('setPosition')->with(intval($width/2), 0)->once(); - $pivot->shouldReceive('setPosition')->with($width, 0)->once(); - $pivot->shouldReceive('setPosition')->with(0, intval($height/2))->once(); - $pivot->shouldReceive('setPosition')->with(intval($width/2), intval($height/2))->once(); - $pivot->shouldReceive('setPosition')->with($width, intval($height/2))->once(); - $pivot->shouldReceive('setPosition')->with(0, $height)->once(); - $pivot->shouldReceive('setPosition')->with(intval($width/2), $height)->once(); - $pivot->shouldReceive('setPosition')->with($width, $height)->once(); - - $box = new Size($width, $height, $pivot); - $box->align('top-left'); - $box->align('top'); - $box->align('top-right'); - $box->align('left'); - $box->align('center'); - $box->align('right'); - $box->align('bottom-left'); - $box->align('bottom'); - $b = $box->align('bottom-right'); - $this->assertInstanceOf('Intervention\Image\Size', $b); - } - - public function testFit() - { - $box = new Size(800, 600); - $fitted = $box->fit(new Size(100, 100)); - $this->assertEquals(600, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals(100, $fitted->pivot->x); - $this->assertEquals(0, $fitted->pivot->y); - - $box = new Size(800, 600); - $fitted = $box->fit(new Size(200, 100)); - $this->assertEquals(800, $fitted->width); - $this->assertEquals(400, $fitted->height); - $this->assertEquals(0, $fitted->pivot->x); - $this->assertEquals(100, $fitted->pivot->y); - - $box = new Size(800, 600); - $fitted = $box->fit(new Size(100, 200)); - $this->assertEquals(300, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals(250, $fitted->pivot->x); - $this->assertEquals(0, $fitted->pivot->y); - - $box = new Size(800, 600); - $fitted = $box->fit(new Size(2000, 10)); - $this->assertEquals(800, $fitted->width); - $this->assertEquals(4, $fitted->height); - $this->assertEquals(0, $fitted->pivot->x); - $this->assertEquals(298, $fitted->pivot->y); - - $box = new Size(800, 600); - $fitted = $box->fit(new Size(10, 2000)); - $this->assertEquals(3, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals(399, $fitted->pivot->x); - $this->assertEquals(0, $fitted->pivot->y); - - $box = new Size(800, 600); - $fitted = $box->fit(new Size(800, 600)); - $this->assertEquals(800, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals(0, $fitted->pivot->x); - $this->assertEquals(0, $fitted->pivot->y); - - $box = new Size(400, 300); - $fitted = $box->fit(new Size(120, 120)); - $this->assertEquals(300, $fitted->width); - $this->assertEquals(300, $fitted->height); - $this->assertEquals(50, $fitted->pivot->x); - $this->assertEquals(0, $fitted->pivot->y); - - $box = new Size(600, 800); - $fitted = $box->fit(new Size(100, 100)); - $this->assertEquals(600, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals(0, $fitted->pivot->x); - $this->assertEquals(100, $fitted->pivot->y); - } - - /** - * @dataProvider providerFitWithPosition - */ - public function testFitWithPosition(Size $box, $position, $x, $y) - { - $fitted = $box->fit(new Size(100, 100), $position); - $this->assertEquals(600, $fitted->width); - $this->assertEquals(600, $fitted->height); - $this->assertEquals($x, $fitted->pivot->x); - $this->assertEquals($y, $fitted->pivot->y); - } - - public function providerFitWithPosition() - { - return [ - [new Size(800, 600), 'top-left', 0, 0], - [new Size(800, 600), 'top', 100, 0], - [new Size(800, 600), 'top-right', 200, 0], - [new Size(800, 600), 'left', 0, 0], - [new Size(800, 600), 'center', 100, 0], - [new Size(800, 600), 'right', 200, 0], - [new Size(800, 600), 'bottom-left', 0, 0], - [new Size(800, 600), 'bottom', 100, 0], - [new Size(800, 600), 'bottom-right', 200, 0], - - [new Size(600, 800), 'top-left', 0, 0], - [new Size(600, 800), 'top', 0, 0], - [new Size(600, 800), 'top-right', 0, 0], - [new Size(600, 800), 'left', 0, 100], - [new Size(600, 800), 'center', 0, 100], - [new Size(600, 800), 'right', 0, 100], - [new Size(600, 800), 'bottom-left', 0, 200], - [new Size(600, 800), 'bottom', 0, 200], - [new Size(600, 800), 'bottom-right', 0, 200], - ]; - } - - public function testFitsInto() - { - $box = new Size(800, 600); - $fits = $box->fitsInto(new Size(100, 100)); - $this->assertFalse($fits); - - $box = new Size(800, 600); - $fits = $box->fitsInto(new Size(1000, 100)); - $this->assertFalse($fits); - - $box = new Size(800, 600); - $fits = $box->fitsInto(new Size(100, 1000)); - $this->assertFalse($fits); - - $box = new Size(800, 600); - $fits = $box->fitsInto(new Size(800, 600)); - $this->assertTrue($fits); - - $box = new Size(800, 600); - $fits = $box->fitsInto(new Size(1000, 1000)); - $this->assertTrue($fits); - - $box = new Size(100, 100); - $fits = $box->fitsInto(new Size(800, 600)); - $this->assertTrue($fits); - - $box = new Size(100, 100); - $fits = $box->fitsInto(new Size(80, 60)); - $this->assertFalse($fits); - } - - /** - * @expectedException \Intervention\Image\Exception\InvalidArgumentException - */ - public function testInvalidResize() - { - $size = new Size(800, 600); - $size->resize(null, null); - } -} diff --git a/tests/StreamCommandTest.php b/tests/StreamCommandTest.php deleted file mode 100644 index 1af12dbd..00000000 --- a/tests/StreamCommandTest.php +++ /dev/null @@ -1,36 +0,0 @@ -shouldReceive('encode') - ->with('jpg', 87) - ->once() - ->andReturnSelf(); - - $image->shouldReceive('getEncoded') - ->once() - ->andReturn($encodedContent); - - $command = new StreamCommand(['jpg', 87]); - $result = $command->execute($image); - - $this->assertTrue($result); - $this->assertTrue($command->hasOutput()); - - $output = $command->getOutput(); - $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $output); - $this->assertEquals($encodedContent, (string)$output); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..f229c084 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,17 @@ +assertEquals($r, $color->getRgbRed()); + $this->assertEquals($g, $color->getRgbGreen()); + $this->assertEquals($b, $color->getRgbBlue()); + $this->assertEquals($a, $color->getOpacity()); + } +} diff --git a/tests/TextCommandTest.php b/tests/TextCommandTest.php deleted file mode 100644 index 8b19cbf0..00000000 --- a/tests/TextCommandTest.php +++ /dev/null @@ -1,32 +0,0 @@ -shouldReceive('getDriverName')->once()->andReturn('Gd'); - $image = Mockery::mock('\Intervention\Image\Image'); - $image->shouldReceive('getDriver')->once()->andReturn($driver); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $command = new TextCommand(['test', 10, 20]); - $result = $command->execute($image); - $this->assertTrue($result); - $this->assertFalse($command->hasOutput()); - } - - public function testImagick() - { - # code... - } - -} diff --git a/tests/TrimCommandTest.php b/tests/TrimCommandTest.php deleted file mode 100644 index b7f5c770..00000000 --- a/tests/TrimCommandTest.php +++ /dev/null @@ -1,54 +0,0 @@ -shouldReceive('differs')->with($baseColor, 45)->andReturn(true); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('pickColor')->with(0, 0, 'object')->times(2)->andReturn($baseColor); - $image->shouldReceive('pickColor')->with(799, 0, 'object')->once()->andReturn($baseColor); - $image->shouldReceive('setCore')->once(); - $command = new TrimGd(['top-left', ['left', 'right'], 45, 2]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $baseColorPixel = new \ImagickPixel; - $baseColor = Mockery::mock('Intervention\Image\Gd\Color'); - $baseColor->shouldReceive('getPixel')->once()->andReturn($baseColorPixel); - $imagick = Mockery::mock('Imagick'); - $imagick->width = 100; - $imagick->height = 100; - $imagick->shouldReceive('borderimage')->with($baseColorPixel, 1, 1)->once()->andReturn(true); - $imagick->shouldReceive('trimimage')->with(29632.5)->once()->andReturn(true); - $imagick->shouldReceive('getimagepage')->once()->andReturn(['x' => 50, 'y' => 50]); - $imagick->shouldReceive('cropimage')->with(104, 202, 47, 0)->once()->andReturn(true); - $imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->once()->andReturn(true); - $imagick->shouldReceive('destroy')->with()->once()->andReturn(true); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('pickColor')->with(0, 0, 'object')->once()->andReturn($baseColor); - $image->shouldReceive('getCore')->times(3)->andReturn($imagick); - $command = new TrimImagick(['top-left', ['left', 'right'], 45, 2]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/WidenCommandTest.php b/tests/WidenCommandTest.php deleted file mode 100644 index 3d8622d0..00000000 --- a/tests/WidenCommandTest.php +++ /dev/null @@ -1,49 +0,0 @@ -aspectRatio(); }; - $resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg'); - $image = Mockery::mock('Intervention\Image\Image'); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(800); - $size->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getWidth')->once()->andReturn(800); - $image->shouldReceive('getHeight')->once()->andReturn(600); - $image->shouldReceive('getSize')->once()->andReturn($size); - $image->shouldReceive('getCore')->once()->andReturn($resource); - $image->shouldReceive('setCore')->once(); - $command = new WidenGd([200]); - $result = $command->execute($image); - $this->assertTrue($result); - } - - public function testImagick() - { - $callback = function ($constraint) { $constraint->upsize(); }; - $imagick = Mockery::mock('Imagick'); - $imagick->shouldReceive('scaleimage')->with(300, 200)->once()->andReturn(true); - $size = Mockery::mock('Intervention\Image\Size', [800, 600]); - $size->shouldReceive('resize')->once()->andReturn($size); - $size->shouldReceive('getWidth')->once()->andReturn(300); - $size->shouldReceive('getHeight')->once()->andReturn(200); - $image = Mockery::mock('Intervention\Image\Image'); - $image->shouldReceive('getCore')->once()->andReturn($imagick); - $image->shouldReceive('getSize')->once()->andReturn($size); - $command = new WidenImagick([200]); - $result = $command->execute($image); - $this->assertTrue($result); - } -} diff --git a/tests/images/animation.gif b/tests/images/animation.gif new file mode 100644 index 0000000000000000000000000000000000000000..c45bb7771e1e8d034cb0e17b5f73709407104851 GIT binary patch literal 592 zcmZ?wbhEHb6k*_J_`=R$>7D$48KaYbylY@=ZnEdI*}Pea-aFe=YEgQMnE8qO#; zSy89+Z4v9|1?)j#;ivng&rOi3&2sv)l({L_zQ5S=(*lmS^SFL2W+~5bxiCSZDAnD; zFJW?t*}+bQV?DBp|GE8KLxPsJYn8J)y_3d`<@*ND%i^x#vAXn^t$K?el|_sz}Az3R}J)-SsxlReDu}cq0a9R zz0PIb!k(k0i$c~2AWVe$gn?Bg0qm2ERqJv~Kd%uDMs*sUEhl7C?3>jGY6B0RE zIOZHHU~1kdr4-qMP=oNDMuI@i5d(qw5;_jA^%|d_Ye>Ja?%+e+?VsmJpI3NX$s`-& zo+`}Iu?Xf8pan>NOHh#GOql0T)bXZi-?Bq;1$(WWdDVFrU*|c*@20^U$bUpo)j*Gt b|DmwM2Vcn@>iXFH1~d`LZ;)6*^P4pQdA7Tj literal 0 HcmV?d00001 diff --git a/tests/images/black-friday.png b/tests/images/black-friday.png deleted file mode 100644 index 129c9e9459f0dcee89f1a9f4a25e89b3e9d50a10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4964 zcmV-q6PxUbP)8pD-|j;!^6Yy@bJ;m z(c|Oe_V)JH*4CMsnYXvM>gwvfy}e~+WwEib8!$PgrKR%n@}Hlda&mGuHa2Z-ZHtSG zTwGjye0)$)P(MFEE-o%cMn)SO8_LScS65dgBqTC2G7}RM3kwS#9v%P&6)Gq!8Wn9ZwP){k+SBv@f7dZtAz8Vg0$yfX-VZZ?7{Ypzm6Z!<^*X&ES=Y`$C#(*~ zi&BTNuicup^LeX6Lp4UOlWQd6tX|`|1_vIyijK9Vgj*`FKSJ6`C#bFdhU~sxueG z;d@0K=9~L#oBTMfCQdRAqDva+GB|vDkYtl!yES(*S`H1srxi38aMP! zaM-caRfz*ygo7p>$eK8UIDfkKoxUC|vvEx($K$X&5{0z;yGn5`J>+rK_^<(oKghb4 z;_R9v!ErdQol#xe`_-m&o6GTdP`I8J@&E%IfjN@s}N9PxitCa0RnF_S8EltG=M>Ek#xZlO<%u6GV(PWe|EbFUh( zp8pzlbJ$zKo<1sY5XVj)bHWdF&(G)u=j&_D2N=2|1|04Mb9BFvhaja$FoRR@jx_*O zdP*A;4(%A!e8$wV_$g#POMiahDx;g;7+GB+E05Dr;nBi7LPwSL8#&5#pKgD}R+V%d zjvhXDZmFk4*;#K|mZ9k|;N3npvk1L zy|naGe2Mhtob@F>62~Qq2r3%9tNEzqBq4{5;<@Y?J70 zrd<=IKt7DfZ1Y(HGgIHggrhj&H6JHg?E0~GJU7q}VLw`MTD0asdmM{1Jky0XCQ|4E z59JMu3z1DxONB|eLVj%A&I(2uEN{f&pZuCS;LJe3K<1dhHgOh1VGtlQFRo*av#cfz^}HBv9nAnaIMD6$g=7k;Q>@J12=flcRAsO)v2<2?r#{evz^x z1KHxn%# z+LOMpB8UQu{Li+d+FXaaDc z%9g_b>~_l1g@ccp!j0!492F&Sk8(pQ6l#x~Rgw!PhEG#C26n%Loh%r{Nl4s&%nm~* zv8q$VOfN+tDar>+-4l7DJ`$|WytC|z;Cj%w@Q$ZsA2xo|XpqmXfunxoG2`Ej+;X~$ zW)pU_NY@72fZJe|U3JVBKI~iOPfIZz()4AHzXJD9Tc(}>i^wPq2}ISyR8SPR!vGAV z^XtiIcY-5#G^I_Gx2f-D;fgD)parLtL%_~tZ50YSu~-`npH8c;KQVmS!N*`54IAcS zlT|q$G!Q{p7Uwb!XuqJce?>{w)t5{&dLC08rx_EmvDt^B*u-WV(=&>)v4t|7;vFGo z)S)pQE{0FoU)VY8!XJ~P|cXE%;ZCyPtfxeP`LRM{m~I=Qs3!J13kElN+_SFXc)CL5Hg zvYi7q?CKl`BuOjK7QQ>LZ7L$&^4xk;D0f)_S+?hVCD^}#d zkd;xK< zFWunuHZ3qfdmM5^3p=THTs}MD-eQTqrIK4oHcc$E6dcs!DV?E+xk1#VNTp$ezRKE~ zvi^wZiGKlD8|EdC(e{^S@POlpPT{Sj{*o_B4(bAw$ui&5& zp0+jsTqgK12YVvuQM!>q3hI_X7Bevps?=~9Kuy~3S%6p$MD9@E zu*3uf2RN;D93z%Ao33ooaQxGgaO^^x){TdTD`>(2_D$5!A-$={n}ctF9-s2!vQpB8eW}A(Us~lT*U*$W0{xV_LbEkY z8+4a))^qVWvXd0rB%Gqh%_NP#$}-^)UzD19UzCrYC>9bMkDsjKz=1_=6O~eJ{Vz|k z+*rSFi$m)Jv+e|V9eI8kT<;3qAE^dXP#JPt3ZEnKl4be`==IglVJo$Grw;PLnx+Nc zq*57G>Rb8NiQhk-^AaNXpimdiU46EwUAfg=Uf?JxT{dmCU5lMKH&ApsxTx}R33fm2$pCG= z6{Nx<4lw`)zEScc)HuHUJrsq>RzTjxs*H8PN>Zc3Cc?Mkiu7xu6){wUh-V@W$F{JP zcr?@$x7U)~bjY_X;Yh4@IH0gGM-p-)Djnukx&lAV0ilsxxoe-&kL4+cL{6=gp?1vh znNS~zvx0I$yY?Cl8ioNmSjRfkmeYwQrlI7fLwd57o-wlJaa~~Wu6RZ zfeQf~w;k@8phn(j6YOi>3*13DH1aUnEZ4Ky5t;kyWZ^U!;cJk}D%_TiLoCDMnS&3+ zG!vMwa)Hrd$wgjXFDU0|YPG^4xmDDwQg3<$4GZ@yGdK(((2|8$LF0AwmAYROz}dJ6 zJnB-vsu`md6zT(yJX9R8-)#K|m5f7v98xh=J8vaLp=e2;`UY(moVIwxkL*QuTJAoq zFZ0~@LpF^EHg7=eIm$R+`hxGt;^QhUUe+R6SX#BD;pkg!aNwmN)6(*mz8*D#QC@*# zedRZ0-EY#A+aJ6U|4hMAu~hPSNlk|uOei?~cHW9Tzm&MVeWD&m>sDEQwCit}r}eI` zu^ZvA9CFN`s;Yi=_ee?QU40@=_3N3{28Z?}G7MUvSZ+uMf|}pVr6in@f&&7pCQo!Q zNjTJ}XH^`2D{s|TQe!RPf^s<51Horj?2@LBuWmzgSIvaYt37k0MLp6IxVo28#@_t$ z9U$o|f9vr~yap2Ptl`>2OKv(W?Hx)Qj$tcrg;Tn_>bqvnBz0j)Z6WKvH@wzHJCcfT z)E`AGLt1oCkQOynK(O~ggr@cazL+hkf;0RiHt4{kR zEUS%QR^h-);I5th-%P?+nU)Jw;Bc)D$9aT;R+Hf?9`j$7)uU@XPAgH&O|Rao!clb9 z<2({(HQK!bN7&&wi%`>H{!I@vjxMx1kHq+)It{oF$F$9`Ri|p9mRy^$uEx=BhW4EL zaz9%y7n6CKJ5H8`VK|*m6RzD(81}Qw$@6qh7o5DX-ygwdb&Qrb97|pXj)&D|l4oHO zj|zfYUF6Yk7!N2mMUP%|Je zC`L&?pR6xgf8Wa$>9LiGNvo{`3n>~_tH*^ieQ6YQ`Cbv9e#MJw zSpB;CA@w1sQ{hRu$MCGNhC_Qqu(h`$E2XP`3GB7#E*OQa zsi=lER1fXQO#4z}9J6!$-u+cY7K<$!FCW%%Xiu!FIJC#h8+ogBo)j;=d1xVf9L^gA z$hu|Ut0}8Ew3jc`#If3ecy$d#GkN21Qm3ZqZ+O#(*%ci6t4WUbR$KP#1b>)<*g5i- z{S1~BFC$@6aBK`;Iy{QF{r3D`Tb}zT>D}k=KN{gs*DuI8^w(M)@>V+%Z~lJs=FNZp zXdG|<+UfT5_vgAe)YUyQj!7LH+vn%MKYsl9H=*(7&#oO5$6KOzpT2*qFqhtR+=$n_ zF-bTKuSBHMz16oLA3uEf^oi2waFjT1Z*Sib?W&2+M0>*<)%%&0kc2~fVJJv$Jih(- z`FSTsqr*WYSN^YP8IWH)n3SC)oi9ER8F%HC@G1ZrUi~~-#^^`^_E_*!=b7I$46=)Kw|b)H_9_N2#4ua>`Xsy>Ge#P>u~h; z;`kd3^jv9M>4`Li!|+1|5|7HubvX9p*h_=`Gy#*qVfq;l8AyktN(XAkvoXfyIMCC~ z0!OwV$IZ>p+qWGKv-aY6vlqsV^f_ACCVXG%I??D#sBXfr9|)a2QmH z;|Lfxc!em(aTE;#q{E@B3dd0}@LQBh9Lcdb2#^kkA~TL3N1K$tzrMtAJdK;1Uq3q> zvP?LRhk;gzG92n#DG%tspSm$CEFH)9TK42i;24g2UnW34b~uDo96#%tlmC1-{X42x zIT(-*M=2S{&qEyz6AwrT{%K3yjs()-00|tow;vk7;44Ha4t=TH@jyBpJ&fb?k+H4L zgC<1(J~d2Yr{@kwPfX6fYYL-W0!MI|mb%pf(%~RD{(4s@w$*u%gvg(jVX0d!ARP`; zIckSf3J$Ua&XV4-&``ggyM;Y1VGt|!D2~&-md*5N)gPn(y+4HsV~QiNPodv%10P_0` Ab^rhX literal 0 HcmV?d00001 diff --git a/tests/images/broken.png b/tests/images/broken.png deleted file mode 100644 index eaecd5c64023152ca7c424acf044cff4fe93b068..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 42 vcmeAS@N?(olHy`uVBq!ia0voZz6=a3NgQkp42-e*>=zjr6c{{R97DJOiY*3R diff --git a/tests/images/cats.gif b/tests/images/cats.gif new file mode 100644 index 0000000000000000000000000000000000000000..307d4f0e52fb0d170511f4d5d472d66194307522 GIT binary patch literal 1721 zcmeIx`&ZI;7{Ku_pbixix#txE5fux(jY>UVLKKvlBHmJ)x6E73Qk$7B5ET(`k@s7Y znrJs~U7VIOb%Lj+T~@AnoThWtX1PwS)7I9soil&iU$D>5&-26kd7Y0h--op`)*o;N zWB_pGV>|!=rf3w(%Fe0a zQja^nfQ~J#ByBfG|30Iv6o6r5jCI*fUBd3eF^SXZToeYi%MzXAfL-m+sVpKYw&OCQ zV?A@5T`kZWp;LE&`3*j`--A$5LVAAXM4ltIu!TGt=s1(%+ni=qwgVS(IRDv&Ol3Z? zW1mI43qE^@YA@?wtW8L#VO=GiYhQ{l@wXb+-EZ=78TKLbvnphbmmJ-SM%u*w^F5oa~xM#o-P`z5Yau zD%L74G2=34Yquv^94c&N;*izf)bMu>f;JaDh=j_Cx3|k9Q%*?KlO7lw_p9ViIGgax{^J6q_r?KSQ80%c$aUV%fI-$rNpJP^odF0y-&ouDCIEZ|fWR$z zJ*^rk9PJRL?NN=%kYv9mUhmln1;Hg{PTSiySwZBKSn~VYb*E{;-BG$eTRuY?m68^p zEEkl9!c7Rw<#SvFEI)4TamM40R^AY%T5a$YF!Lv)o-T@lMY1m%SSH<195{|XR}J!( zvSMv}*@tSlJiS$5cPhFZwCFfECq>S<4=Na!XDxC~pMl1t9yTutVnHRupD(vQnoGBS zg10yDfQbdTByUa~!+b7jEmk$12#D!TKD0e3BqQ2;96qowhR7i^R)eC4uD$qSRBCJ! zFns;jCGBanDSR{C1lR)L0o;1}Z2$(hq#*$yACBj-c{2;_B51HcOc+(Mi-{h#IgmS# zx%pd+is=lPYO(@mR!T=sw)+;u-zrVebT0DqjYZ`G=2|;PLZi-xM~J!XGd5W$Yz8J7 z@H8zhS(d+AB6aCo*QvwZfC{zH|LAM`K*$5A@#H)r2Ip9IF7=b95a7)L023p>88US2 z$rMo^)w=LU->TM)z6-m+o{a;L@Y&()#c{dRC2~-Rs3dAvzBYx?8DuJCtFxi`V5R`6 z-)IO2S>YgqxLHV8FC=^@)NK~R(!i?9R!tG~B+CK96l-LLruRw2W$!Ts9_>y9``C&C zB6EueyYGNOfqjV4+>BCeT*ov^R0rOR*VH+TxYh|zixj&G`^=w0r;7{oTm?={AH?BdLzRzqf(jE&ZF6C_K&m)0C7DkwA2}@k3vv*F`(|i TK8aaq5;Hw^f|?J30K5MNs4O4@ literal 0 HcmV?d00001 diff --git a/tests/images/circle.png b/tests/images/circle.png deleted file mode 100644 index 0ad4e6bdafdb58ed53f52ea8b123c55a63406d07..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 383 zcmV-_0f7FAP)`e_)-1Z1?M~MNpkO3v`TLieGzzAE( zhyvF&0t86V!Zy+(S@H~p$Y49k5Pllsf(o{?3YSkpJYWa$cqdGV3U)9RLd-tc8SJ34 zxgUT8c5um@d!qFqNc-PCQ@}h?{8e_0Fi(uXl`|#GGv!ZJ>;Uu3@V#nIVV+9A-Wv_f zQw;*R2tF7I;-84ykxbj?5=Dj z9~}sxw9Irm389p9h9LoPzvopn-FN}V@5squ689k=24h_ z)z{wpIOp7R&pCVU*?V>BFVrtE(nL)vB9zIXn-D@Cpl0HHTb)DUx zr#3cdXrPHAs1Xa#r>Gd|_dx$4>SogKg#OukB;wDw7?Wf)?vW+WHIi zH;|ub^vQGvQT4x|E;2&G9hk2E8*~);JswYo$KTQ65Bj{mVDAdQe?@O!cXw}hcVEy? zN~19ci)*UW=j-h140Lq`db+y0dT`a%V@?Tv5C-+9P|$+{D8Nu5LcS_ zsVyL-lOhEK#)Ux??Qpu>o(``M9HSjcA)2v}0Yo_{hIY_Sx69*X{Bb}A8OMz)qt3Bi zTzBZ;oiSI>u~Uzy)~xN#K3#|pYDb<+yVo7hUAl0Y*N3h-efF;PEMyPv%O*7QRijchV2F1zn$eA1K~-f!F|8P)s8q`s zf%~{k%Nic9Aaiq44O65f1JA)|lc%Wd;L2itVs9Qm=3?fA8BJA-Ink(Ab{1~u0qI9G zNJA?86%mVaNJIvzq6%h(ycL@oMubgDHk5`${z6rf4M`y^0pCHW)0usrFfDg8WkR}95c0+cLh_8?o*Gxi{@De2}wF`9$z1zEQ-J4(j9J(wuV z!l4ZUwjL3paDb+C4vaBkl#uUGW z!6LN4J1uxtD$TVbd=>&^v+40(VcsxhXoPLrYRNuYPjFq0MWNYp2QvMwlfdwPtr5y= z?ePtS>lHHYAT?AJnFXIXT)d4<0uD=P-zLy06fPD4BSQ@zA}CY?a_Yg8HY7&i`=PdI zh6n_Eegi^yz5`=~cUFDL!n}sjOQPx@1xIY*!Mv?~NN)u-;c3|I2HYc`Pt%U8@sOE@ z%9I`t&AHfCUNnmoh!GMzGDHgj^`j`j8`}qy+NBkS=bE;*(MwOlM2(3`RmL$5pI%%A zwW#cHl<55PWUHowr;feRH=3NuM&K zkpmyhO^2q)EKHB+I8=B`U`NGI#QZ+N@wN}ngUiR+<>Tzt$63?6ZUk>Z5V663umi0? zV-T=aRDi(E!ohD2`UX5Y=~aND`+X=_l!ilM0y8vMFuxIQ^ZG@h`i0KPIm4(V!(l}q z;PAC^fLF`m8dnKN2O?o~%a&S&;}3`iTM!{aj)wmF-S3B3Nf-_78OlU5m9#h~O&!+6 z+~FO0{_p{QL`{fM>xS%jnNQD zYN}AK*ld@yl|?A&vIOK-2qOMjoUYwW*G1uV5D#^4aa&Vr_!&%mPQO!%&qF)tS zW{7YA7Dq$)XNLaBaDOzBho2eXe<=2`NGutNn4}q1kcx+vA|<~_w2^|(2ym!=Ut)nz z7FDgxfyPpqD~aLTD`F|c+J;P$FA1y+;>C#=nM`t8(G5=F#p&_U5NJIhNkTFb9|kAf zJQ&#=izJ4l(c#E&d@M3Jyg88ucxuF&JFfCo{9diO!hbQ>JYjJ1hvET#56bf93uBTdmNu+%8*S*#gTJShm2j1(q%Fe`JB?rASoZXt4lSo|dc>T(%lnDVM|Ha5`L0 zr>nySkI&&R_JbzpKOBckR&=6Wbnna`*GI z8&|*i@)ew!603LLZ)T_7B{?-bwRf)enJ+%}tslSe+B=&@ruRvQKKtNTzx|UJ|MZWW zlDF-@{qVgfzxJJ4eOh!^1FTas|hUv@z!{kl1zb&SSAtk6-F}`nd~h zQoY%Nb~(OwFn#2jFnzH8SfCRT3{jM>d^o_XS#jhmi- q`O47~k388f^0tXP)KLZ*U+zZK3<12uwt~|df*uJ3vUQf-iKjLrpU5Em_ z07>B+2Ydjl2MGdd0rZyZAfN>3t*4U#s3)K+{!su1b!g-2=2rB1nx@(m_0sF>wh>=8 z`m%C$40W{P3*dVL;3$i>)tN0ztCO>Ye>cnL`YXLpQGhzx?7AIy7w>=m>|DSnOB*;a z&P~yh0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F}0001* zNkl$ zVkn@*;_=-S;&CEhCFep}WXe;{>9K+4H#p&cWINbc=e&rVA|l>7YnZ9ll2eMRszFs_ zO1adl5ALzv+KdV304I^f&)w_W;A8 VHj8nfw%10P~g% Ab^rhX literal 0 HcmV?d00001 diff --git a/tests/images/iptc.jpg b/tests/images/iptc.jpg deleted file mode 100644 index 849dd0a3f9bf8420a4cd8501fac3935f3ebe6e5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10526 zcmeG?TW}l4k+X{z9}q=~lqEYX7Ysce2gCv(KoT(}5g;Yf5o{U&E!%ZfuEp*ETxqcj z?+!?cA1PZ_;v_$bUwKt3`qVXh1NO$*XGugDnf+)nw>m7_`2NhI-H- z8uW2d#1C=4A+Ghmpd{D&9(Nd|3~=lMf$8N#9PbYVLp{BH{V*}Sl^o)IcI6=A{G5;X z^MO#XC*TXGpmNCPzhXxsFmt^)9KH4SWN_rJ2fm)$vv+6l@k(mkIP-KqwD0cH`Ezed zX8Mu`AGu@y>^)_9?umy;X4f-IFXOi!J^SRd%~#$&df?uNKl0dp-+S&Szx>iafB*Sc ze|1B3<)fee^1uAxzkd4biDM^ft9O3pAOH1-|NYu;h7iw#w0TgH5w1w=@Ph=m zMu!8*+wU5o5S!kHeI%=KUsV@`K z$j0NEIVRG$F(&Et_?p;=C&q+0y87^1LzGTo5~<*tqD@Et|6AXQMihBEdLmsA3XMEo zR_50YTw1@jEUllCrsU}1Ly@c3vTOB59TPFKR#!DMyEYwV%(GCY=y){3NXV(_DD&pX zjfKTX9wdvT$I>xL5R#F^SYmt<%=&={#H(ann20CRvBYFn$YjUUk@gjZ&J4MlEzTZo zcLmUNw5`+X>gw2PYD_n3@x;{BR9r~LlgSuR#LUwg5!YgxxyR-(i%rQ;8br~x2<0eN z^d^~(f}oZL^@hWCQ&ZW5vgFV;nuf|cm!&vXaUE;K1hXcn_Ka!64$)2%4{N8IjfLF^ zEL$jS-oPHVdfn;5By%gE#ybtNSw7vs@gg?$rXk_E6%cce-PuBeNaN5W9U6xVSV>}f znM97eDVUs0HK%`QTU2Vx#B^GFRJ0{F7>(0PGA=+biFIsMyE-Tg3n~|~= z)I$nWTo#Gw5RbZU?x=5(~ASIMeqU>KxTMLMNo!%aSqMOjreQ0AB?Qn_jJBAetV42580I_h5d zy<`N}bmR1Nw2VzsQB>JoOEqKG#t;g?a4rQ?8KzoChrB|7ORh=QE26aQ=29Ze@blO- zvF5JG>rIW&zGrchn9{N;YM$=PhNzi!#WcYtMO?)O)+A8c724d~7BrI>O^F&1rquF!1oShIRCd4F8$I_{c6dM=ErIcGs5`fL?#dT+?3t+ zI&d6C6V<k_=tPH^*TNGE1Dk{Df+#g(p#-Edo8V%jxL6YV5 z?UkT}Z*7-U<&b-FUmd4m9gq>LWD&+a3;-YsQE{8Yj7l6{G-PLC9@b!xV=}IaO_f9s zxs1@w-)cBEebWz$Ir)##M>vec%n;1*DKQT9IM&J7AlE^erx1$zotEemW}V9Nqq z7TB`D-;o76o2OWVxBFGt8g0E1KHK>oNR0_-GPh9hy#ZUu2=WJ3>VvnRtnO`A*URp3 zhQSF3Pc^UDu zbE7;){jNQ#QNGsILO}!Gt+-KM>mo6`VA2Jzp&c7P(MS1puR_d<*7%03^qMtO{5{mN zFt_N`LHrTxhuAFg_W_pSS?hiVx$SLHK^g&Cr7TLuiEDauYNo&YN!EcShLk#BH^OL5xty+%NUh2S?Gx#zJ`xfA4&2Coh%)&mjgfv8u0zVaD zB%>Hg00~VXcVBKCox$|yx!eSH1tn_ZwWg{9MDz1O$PQ_;d0pkC)Tu8@gm%qBSsC)~ zs;<=lX4i3CC2lxJ^m-d+ViaL7#RUgVRgtiHgL>SA=A5UW0ILJ^4)}!_urTZ59jY06 zv*AGnVLJ}?iLnMbKZL?_CCc5}I|g{0*d#h^`9fxeU>OjIW`x?reHJmr(3*vMEdr1C zT7Ms;&dPH)mZ2+`@x7RW3E%u~nxLqXvRL!r1|-DC zaxLpKs#3EpwcS#F-bO>qP~q_stmq@!Ao!lzeH#| zngLhRQ3YHof)>#-lnMMyR%!sn@SmZGpgby}3}tAoBKx2SKKJ}Bz0Y6u)sbtyvG#|T zhM)TK3hRA8s~cc_NMAyJ-wFk2v9<{5M-~}bnGyqzij8R4 z-i$pB@0;OEl4{`>4e7{Dlmoj4B|~qVfE)tdoTgc8+k6AGq6jkOm;<|_c-XG#S~<4a zc((QFYS3?2fNTz$dKVlFqgS6DNfGZlL`7??LsUV(-yiS?1A$;~5PtnV!C+5+xUa9j zuP;0pW>@=R0o`{l6bfw%Z`(aMxchHDLDdGKJoIR0S6L=cKJ#+V{yTd6c3*n--npX>KX${jO9wA|>y@|Z zK`Pw*$bHsfstcT@nw-CJdF^AL{ikpI`wKt&?UhptHz}t-{<*LG+kd?H^WVKcd(F)! z*FW+3uYU7CU;4%GtwUG7KmZPc`Fni6I(xIC=e}kF*Mr2tTW`NB`M}rDk39bLxjng^ z#ftG}YVUad%q4f1_B|*)@nXeN;-3KFc?{hE diff --git a/tests/images/red.gif b/tests/images/red.gif new file mode 100644 index 0000000000000000000000000000000000000000..408dff18335cddb345f42b408c795decce3c7f6d GIT binary patch literal 47 zcmZ?wbh9u|6krfwXkcLYpOV7Bz@P)fK)wJ20~23M|H{*E`4`XGa;tl@9V>%10Q4~o Ab^rhX literal 0 HcmV?d00001 diff --git a/tests/images/star.png b/tests/images/star.png deleted file mode 100644 index def6448d8fd404d07058f5b250dd3302b50ce3f5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 463 zcmV;=0WkiFP)5yNie))P-b|}pvCZrL7U+Lh;{+-f#Q1@B!LQ4fLI%db)YneFA3GmjNKj<3LMV_ z#7$84ejxr!t|8FQ*iLC+ReL#Exh%W;13rZZ22DQuth?R+Ss2dc+z+E6d z19j9aQlsD=5C@WAIX0jSHRB#RXGz5iQQC?f@Z{7@h^f~u7qZ559?VAKIa!T|sQ1^^I4V?IVO6o>!-002ovPDHLk FV1g$Yr*Z%Q diff --git a/tests/images/test.jpg b/tests/images/test.jpg deleted file mode 100644 index 4bb6549141d4179948fe680537487b31f1652f68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9183 zcmaJ{3v?6bl^)rOQG!eD-2nBbfXbdtTUnS?BBq-fDo$zoBHQjJBV}+Ulh!jX2I1^E zl`TIK6sKV+dBCPCIkF1r$=SNe%-Bk#NNy#WM<|BqQMZ6>WK}lUDQRS55RPL*Y1n)J zk^CarL3qITzyH18cfWi8-yydz+`dQ^efQz-JWR=C6eWXS)a@ko4XQvcm)|8Xxa+Qh zy9?m=Qbj?5Vrk($_bk2Vp2DI+@?>AqUlxDGO=L@!Ecr~~XFgX{^tpSNEn9Xkepz;J zF|kLl%TESBqZI>}K3&RNI&*W+LVNBKNQvN1Sn&tuHjl&wky?s^7- zYN(Pzo9vK=qN>w&@chA+A`%ip<$vK2r758bZPgT|v1|uV1cIIb0ufYe$cw6e$OoQV zviX2#76|4`ompi9&$SAr%?6$jCmRo5lTU{cC43%zwqF_#DVz*+(Ww}spa zbc$uagKf7mBwIA1+Zj?f*`YjY%tyoI+FSIIbN;HB>z5y^K?qR8o z%3F3?UQCijvY!D_f@tAIoq;mSmsBfkHXAtR6R#Y51-d+nQY?Mzza{nxW?`aukv&RY zd|^Zhi=?8=uQk9_D#xFZl0}sOObm-9pa6kxOZ`_Rm>SU3oTN)AC6!0De(m$b6V$jE zrc5R`zCd6?vY2U3(j^qY%u~E{n$kf&kl`IL<;5$1WV2ziiMee_Lg2AQzP0`VG?Mzl zwtxm224qXN-5)H1MW3>5@v8kcFoO27l12KdY9L0TSi83DB-mgdA`&PXiiEINRJ3)g z;R!T?=VFm4mHYP#Z=w;P%wrElBBQnx7t;gB!HDchTE}KU_9$EH+O_-`8bKsqAOitO zgdjQ?fAX#0q%D60l1Nas$Q}`i5=5c`M?UbhE;mWA#c+~P zI>H`!8aF`p(DE?Aq=~7cj|lCv%`IXqwv~$k|Q2AL?QDWyY>ObcR|tcT1XC1@W*GBxFKm;Y`s}lA!^`mGJ1%Z zH6Z4qTsgqcAl31cQ1JZp@dbNgJFBuN_~~C^EU5>8nR$7FAA*-10t~W4N^0o?xguh% zOyj6V#4ultXrbw<+rOtixA=|%{SKEDa!1L7(Mgd6UV~EtPy!FoIUvw8kVpxoS@kel zUw=W2%?f_pMbqDelNL9I z@dB9wL-@fdMfJh;=uS95Bfu&6wss)R@4tg#$trvKUCT}WOUlJmWUa5fyQ-C6n@0gZy5x!3xOZCLm0g&%&XJtkIZD+(^d(y>rG)(Nu)eINR=xcHAflGAIqMy9 zUx`w(#82)hZZ58tlGQ){sa7~3$4|hI3y>6Q2Ir~t!GXKw6-x274RSg3E1nMXtOYs% zah%fCKl#bBp{id1>#AQ$RxIB-m}7mN!F1Y8t4cA&Mj)PvT=1u8rN<;%-!RgLdh?2E^H@3)DsDu{UR@I6k!xwoa5 zu1D+Q@>Roy49=(n{5Tk~U*{JHz6B-Nzn1ShdS?mnhc>xPhW8jNqFpeiV6PoO)LI1` z7k^z)0$d2yLmJWA_1gtjLb4Wo6-u-UowkMLLtiABf{Pbz*iJ3zAVM;95Zo-lO84s) zTPY5#)RrQ&T5LF!3+K%QL<{G9F&GU7JPGD>4!1#~a~;qKPuw<-Mr<`w+}1qh0hrAK zzi$zZsB<_Z<>+d7496ZhV&JR#8PE}!i;C_dR{H#PP)62DrY9j;4kW{4+&W*$St_z{ zX!`tIQzLFr1yPiA#0tN$ErdgHlvH=fm=8ReOGz5pr1fl2cYK5nXZ8SsyEYEx9Te0~ zk-dKexa?fb|AI@2DPipt%B;1kEypm1Cp5u9+o~cP^B-hK0U(A}n$Hq|{izLd!4Emu zfQDS*kcmH?%pRtMd@$zd1)Jev1hFscC}oRUA`iI{!Bhm514Z!U`bucW$u&mwg zI333=9@%zoomLa|L^PgAsVY*c7DeAd;#12xcRC%6gRwgpMo*kvtI*}qM>j;aMZIcI zRP=a6~N%YH*6EJtN?f1p}$+0SSU}=sEo< zaFM`7Gzdl&j-r!S?fp6U%z^;|vS6I7>mPGqJW&ZugfI|M{{d<*HyqKK~_rpyH zMys6z6ZSxYz~6-?1mko%k>?y3J@DsvGM)vanFq#m))VzUu^5b90>e7riRUU41>mKs z92j-%xj8Vo%Gi-VuIBEAl>xU>Bs`)m{|5<-1JHZf zjsEuj1z<2Q{dR!Ev2R*PWdICRL=>T%;V|&$)vnv|K|9BB2$@s{!7!Yjbvk#Rn3Y+0 zKA33ad(UKLhHHs7?Vuhf$F|qpwILb>nSszyW~K0`BLGHow*T%qndxcgEEtDFTs2Q- z9w1JIVu(iH_I>rsAhX%Z02cjr5E{pJ?0get2CIn7G^kCijCS3+Z5KP{z_6q;plkqB z%bn0-&&;ok#;cA-ww-(MS*Ozht4L*tHh*n*a@_Xq&fmx-Fu+#CLc&O#t=o2P$7RA9 zzy~d3eH?_dTCV+scQy>6`fZVfIU9fQXR~4Ubf7q;(sb->Z-4UzKqEB`hJh*}8tt}o z^b@mT7=ng`akg{q{5yaJ87N(MK8&*Y9xC8%pY{>@@tw1zp#reB9Q*4x+H3hYku*>Z zC;&Kvh*FsIar%h_mVFkDqyP-V|9%_x8HT|LQ2Jd`n;3+lAKwRZBy))d9pq}$4nA*X zYt#K7;GynRixI8*?D^P(G_C&^NzYP8J6O=O!_iS&%k$!+AQh4q_+-(LF!bZUBVinA zM9?AQq|yto_IdOWFZ z0=P!8IML|22hoRqk!WB~2XF?+B&h*w@Vs>voW$-&OG`-{P;@p9t^Zey0}kMl&Q%9< z2!(12;0eRRGEGbNNmzCk>oLTXYSwMayu)ozG^aLA)K5z^qe$yO(e2Ji%+IwD9R z>VaN@4&4yX`p~Z+d?1{J;pW2d0>~O_1LXv*X+UeaFtolFYlEaoBA5-si)SU$BBfe& z^zB@2Fcjm*(qKb498jA%7ycL=-}ec(*8=JKYg zBUejU&MMT7i-BlF4aoYK2BzB@tow71^+rpN*-57-t%9nvM-NdaB7#30diqLwrlroF z80m7GJbYA08ClLGoU#U0nYQtvWBI*trk=9~0x>}?27{LzEK_fI{@9-BrW;MuCQaX( z!jM(uJxPJ@^n^2(ngby&e)HAOuI_2sRC6Gl3|XgWF7D9BIrE6u9CSa}81&q7KbP)n z2*yUsGnKSe=%?eR+Oe{*XD}S_#uy(r@P6XjWX-`fwUZW;+fM7_3A@X}Su;MfxzgnE z$Bx}M+B9i4n>JfUwHnW$SE~{F)@0H?S5*LKH+oK8yUO3TVKi0hI*!+>1GqOZ^SzgyjIr`)W$~RLlpzPV{z7K zbU=df%i^F=-gToX85@nwy!!nYk8~v~hP<^Np*9^60s#SLeKaWey)ia*J#%Y17$1vw zn@1}W^))V`)*nu$I1u9KsS$U{=pIkcuruRLUA{R~Hl`X+Ua}bKt-N=SD2kKJ5!Gb9 zq5WpEa_<-WZ#LZ+I4~$i%pqf(ZPDN%DQ4OPZ_I4kG*q{7?~-?>YTPTVeT=m;STP{- za1$7ehDC30KU?#Hpb^Sqp{9@BFHYPrZE8xMa?)n=5tVn(R0C~q^h_D7Zi}f*n7mrG zo*7Fuce+odda_ci)MO&O=YvN2>* zc~fl`nr5ArnuE)&aG->Sw`WFYHg7y>?ini8botZKNNHJ@e~Pg?^>AP$p-CdU`x*|e zFx8oMXRc)~Cr`Vpmh!^sKg9SxixbWWs~7HsA<)3k)rpyw-5&=+313@8HPLm&KOyW= z2Lpl-Zz)fn`eEytZ)V48MNh`=pdGZU z($IL+)pR3i9v#R$wSJ{b6$u#=^pV{W6@Rsa(mKGZG1SB4xZ#%SX(-f1+z} zFwFOj`fnuuUY=@m^;!eri2v$x3vD<1TugV9XTr@~7J4h6UU_iMiHYeJ;grv(w|XMp z)6WY5e>xlp^BFF|Sn6Bq-uL%yoF4v+$0Ka25d{^j2#DU(2TPny5wqWY_*x`XwSMEl z_cEh(8)-*>+&RJXV|CB5H78FW2#e8R`4v7n@KNKjduE1q$9S(QEQ-+#`~boxENt9p zHrhu|yGM@>FTHtmqbo+on?w&Ulve0z7^`Jt6>J*F;ZnCY4oyvby#Da$CZjp-(pv+3 zu#E3Y^FZE&d!;BQ15?*0&DU-{5^4?^4h&8<@qEO+de2xbKiS|a>*A9!Uqk=&Q)X|b zZly~UcK0zppT+DP>FQglH#!og@~f+l9@#b4a&_ZJO`*i)9+Te_PWE#&b2(YMeua4y z`eVAK?qcTpt?%{r(>1-(fF~U>cS06d0+Ar^_mBIh#@=rUS#N#c)FspzOe%l0uUyaA z^?J@6XYC_n1E9jX_x@fQOF0rg0B&SP()@%N40u9%qwmQ2&P-^iJXz6vZ0Ro5m^#zY z9u|d57N%QpFQ?fyF~qTxJx__5iCgO%4g_OqzN>58(^(14egVam3!B{deVBU zxm3Hp;T;}Mk0_kZdjyr(DbBQbQxhM5tz!7_h`-0gdt(Fdq`L+~1Fl|}ff<+i*2-%w zb!U^ceJem|W*0-#BZJY1aH*LWy>%ngrYqjm4HwJQvtE1 ziOHv*OZnQw&fqCmB~5eval1Y>;@!2U?>+Z_xdtYzQ%qZfNp!D-UP{uYb%H9=JJ6qL zsBzU*UEJ*tMIMg#mcj1?Dxrk+2vnjj_hKnW0UZPLG?R&9|yf zHXmz-k!QD$mZb$%h)ei!qVn)H&mT& zKDyC;oo<9vDC*r6t88>vGL`1$qtoG=dk?x->gf~FE9C`G;2R zd#LFv7nW5w{`K(XvfV%a@W<{imi1`=`9|vDzuf=s=AZAygo@_^NfD)lAOn(6;{O2q CK%zqc diff --git a/tests/images/test.webp b/tests/images/test.webp deleted file mode 100755 index ecd28246eacd3d168cc855baf289aab6a7effe30..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 82 zcmWIYbaV4!U|RvEwADaz}vCfAWgLl^a5>hU5Q*zRc z+T=m2n$d^67+o=@EX+@*4w02nv5~GmRvMl`7C?skC`c)2KUN?XC=M$QC>|>wC;=-0 zC=n}>P?*B>_K6`gtJDvMI7|Nc@rx0UOveQdB|iG}fZc3JPB5Mr?Ms}B?*IS*07*qo IM6N<$f^76>`Tzg` diff --git a/tests/tmp/.gitkeep b/tests/tmp/.gitkeep deleted file mode 100644 index e69de29b..00000000