Skip to content

Commit

Permalink
#86 - Allow wildcards in conversion chain
Browse files Browse the repository at this point in the history
  • Loading branch information
stackpr committed Dec 12, 2016
1 parent baaa335 commit 209fec5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Configuration/ConfigurationDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ public function __construct(&$settings) {
'chain' => 'rtf->ps->pdf',
),
),
'webp->jpg' => array(
'webp->png->jpg' => array(
'webp->(jpg|gif|svg|tiff|wmf)' => array(
'webp->png->img' => array(
'#engine' => 'Chain',
'chain' => 'webp->png->jpg',
'chain' => 'webp->png->*',
),
),
'webp->png' => array(
'webp:default' => array(
'#engine' => 'Convert\\WebP',
),
),
'jpg->webp' => array(
'(jpg|gif|svg|tiff|wmf)->webp' => array(
'jpg->png->webp' => array(
'#engine' => 'Chain',
'chain' => 'jpg->png->webp',
'chain' => '*->png->webp',
),
),
'png->webp' => array(
Expand Down
9 changes: 9 additions & 0 deletions src/Engine/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class Chain extends EngineBase {
public function convertFile($source, $destination) {
$links = explode('->', $this->configuration['chain']);

// Allow wildcards for the start/end
if ($links[0] === '*') {
$links[0] = $this->conversion[0];
}
if ($links[sizeof($links) - 1] === '*') {
$links[sizeof($links) - 1] = $this->conversion[1];
}

// Iterate through the chain.
$s_path = $this->getTempFile(array_shift($links));
copy($source, $s_path);
while (!empty($links)) {
Expand Down

0 comments on commit 209fec5

Please sign in to comment.