/** * @param array $options * @param string $path */ private function prepareOutput(array $options, $path = null) { if (isset($options['format'])) { $this->imagick->setImageFormat($options['format']); } if (isset($options['animated']) && true === $options['animated']) { $format = isset($options['format']) ? $options['format'] : 'gif'; $delay = isset($options['animated.delay']) ? $options['animated.delay'] : null; $loops = 0; if (isset($options['animated.loops'])) { $loops = $options['animated.loops']; } else { // Calculating animated GIF iterations is a crap-shoot: https://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=23276 // Looks like it started working around 6.8.8-3: http://git.imagemagick.org/repos/ImageMagick/blob/a01518e08c840577cabd7d3ff291a9ba735f7276/ChangeLog#L914-916 $versionInfo = $this->imagick->getVersion(); if (isset($versionInfo['versionString'])) { preg_match('/ImageMagick ([0-9]+\\.[0-9]+\\.[0-9]+-[0-9])/', $versionInfo['versionString'], $versionInfo); if (isset($versionInfo[1])) { if (version_compare($versionInfo[1], '6.8.8-3', '>=')) { $loops = $this->imagick->getImageIterations(); } } } } $options['flatten'] = false; $this->layers->animate($format, $delay, $loops); } else { $this->layers->merge(); } $this->applyImageOptions($this->imagick, $options, $path); // flatten only if image has multiple layers if ((!isset($options['flatten']) || $options['flatten'] === true) && count($this->layers) > 1) { $this->flatten(); } }
public function testCoalesce() { $width = null; $height = null; $resource = new \Imagick(); $resource->newImage(20, 10, new \ImagickPixel("black")); $resource->newImage(10, 10, new \ImagickPixel("black")); $layers = new Layers(new Image($resource), $resource); $layers->coalesce(); foreach ($layers as $layer) { $size = $layer->getSize(); if ($width === null) { $width = $size->getWidth(); } else { $this->assertEquals($width, $size->getWidth()); } if ($height === null) { $height = $size->getHeight(); } else { $this->assertEquals($height, $size->getHeight()); } } }
/** * @param array $options * @param string $path */ private function prepareOutput(array $options, $path = null) { if (isset($options['format'])) { $this->imagick->setImageFormat($options['format']); } if (isset($options['animated']) && true === $options['animated']) { $format = isset($options['format']) ? $options['format'] : 'gif'; $delay = isset($options['animated.delay']) ? $options['animated.delay'] : null; $loops = isset($options['animated.loops']) ? $options['animated.loops'] : 0; $options['flatten'] = false; $this->layers->animate($format, $delay, $loops); } else { $this->layers->merge(); } $this->applyImageOptions($this->imagick, $options, $path); // flatten only if image has multiple layers if ((!isset($options['flatten']) || $options['flatten'] === true) && count($this->layers) > 1) { $this->flatten(); } }