Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Imagick
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 getOverlay
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOverlay
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 overlay
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 flatten
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Image\Layer;
15
16use ImagickException;
17
18/**
19 * Layer class for Imagick
20 *
21 * @category   Pop
22 * @package    Pop\Image
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    4.0.0
27 */
28class Imagick extends AbstractLayer
29{
30
31    /**
32     * Overlay style
33     * @var int
34     */
35    protected int $overlay = \Imagick::COMPOSITE_ATOP;
36
37    /**
38     * Get the overlay
39     *
40     * @return int
41     */
42    public function getOverlay(): int
43    {
44        return $this->overlay;
45    }
46
47    /**
48     * Get the overlay
49     *
50     * @param  int $overlay
51     * @return Imagick
52     */
53    public function setOverlay(int $overlay): Imagick
54    {
55        $this->overlay = $overlay;
56        return $this;
57    }
58
59    /**
60     * Overlay an image onto the current image.
61     *
62     * @param  string $image
63     * @param  int    $x
64     * @param  int    $y
65     * @throws ImagickException
66     * @return Imagick
67     */
68    public function overlay(string $image, int $x = 0, int $y = 0): Imagick
69    {
70        if ($this->hasImage()) {
71            $overlayImage = new \Imagick($image);
72            $this->image->getResource()->compositeImage($overlayImage, $this->overlay, $x, $y);
73        }
74
75        return $this;
76    }
77
78    /**
79     * Flatten the image layers
80     *
81     * @param  int $method
82     * @return Imagick
83     */
84    public function flatten(int $method = \Imagick::LAYERMETHOD_FLATTEN): Imagick
85    {
86        if ($this->hasImage()) {
87            $this->image->getResource()->mergeImageLayers($method);
88        }
89        return $this;
90    }
91
92}