diff --git a/src/Configuration/ConfigurationDefaults.php b/src/Configuration/ConfigurationDefaults.php index 9a5b626..164f100 100644 --- a/src/Configuration/ConfigurationDefaults.php +++ b/src/Configuration/ConfigurationDefaults.php @@ -123,7 +123,7 @@ public function __construct(&$settings) { "flatten" => 1, ), ), - 'pdf->(zip/png)' => array( + 'pdf->(zip/png|directory/png)' => array( 'imagemagick:default' => array( '#engine' => 'Convert\\ImageMagick', "colorspace" => "sRGB", diff --git a/src/Engine/Convert/ImageMagick.php b/src/Engine/Convert/ImageMagick.php index 664ec84..133d8f9 100644 --- a/src/Engine/Convert/ImageMagick.php +++ b/src/Engine/Convert/ImageMagick.php @@ -48,7 +48,7 @@ class ImageMagick extends EngineBase { ); public function convertFile($source, $destination) { - if (preg_match('@zip/(?.*)$@s', $this->conversion[1], $arr)) { + if (preg_match('@(?:zip|directory)/(?.*)$@s', $this->conversion[1], $arr)) { // Create a temp directory and convert the images. $ext = $arr['ext']; $imageArchive = new Archive($this); diff --git a/src/Engine/Helper/Archive.php b/src/Engine/Helper/Archive.php index a567976..6edb54e 100644 --- a/src/Engine/Helper/Archive.php +++ b/src/Engine/Helper/Archive.php @@ -59,10 +59,26 @@ public function save($destination) { Shell::arg($temp, Shell::SHELL_ARG_BASIC), Shell::arg('.', Shell::SHELL_SAFE), ); - echo $this->engine->shell($cmd); + $this->engine->shell($cmd); rename($temp, $destination); break; + case 'directory': + if (!is_dir($destination)) { + mkdir($destination); + if (!is_dir($destination)) { + throw new \ErrorException("Unable to create the destination directory."); + } + } + $cmd = array( + $this->engine->shellWhich('rsync'), + Shell::arg('a', Shell::SHELL_ARG_BOOL_SGL, TRUE), + Shell::arg(rtrim($this->getTempDirectory(), '/') . '/', Shell::SHELL_ARG_BASIC), + Shell::arg(rtrim($destination, '/') . '/', Shell::SHELL_ARG_BASIC), + ); + $this->engine->shell($cmd); + break; + default: throw new \InvalidArgumentException("Invalid archive format spec: $ext"); }