Skip to content

Commit be47fef

Browse files
authored
Merge pull request #32 from pbories/MultipleSources
Allow multiple sources as first parameter of convert() method
2 parents e3e3cef + e828a8f commit be47fef

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

Tests/CommandTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,40 @@ public function provideWrongConvertDirs(): ?\Generator
4444
yield ['./', 'The specified path (.) is not a file.', MagickBinaryNotFoundException::class];
4545
}
4646

47+
/**
48+
* @param $fileSources
49+
*
50+
* @dataProvider convertDataProvider
51+
*/
52+
public function testConvert($fileSources, string $fileOutput): void
53+
{
54+
55+
$command = new Command(IMAGEMAGICK_DIR);
56+
57+
$response = $command
58+
->convert($fileSources)
59+
->output($fileOutput)
60+
->run();
61+
62+
static::assertFileExists($fileOutput);
63+
64+
static::assertFalse($response->hasFailed());
65+
}
66+
67+
public function convertDataProvider(): array
68+
{
69+
$singleSource = $this->resourcesDir.'/moon_180.jpg';
70+
$multipleSources = [
71+
$this->resourcesDir.'/moon_180.jpg',
72+
$this->resourcesDir.'/dabug.png',
73+
];
74+
75+
return [
76+
[$singleSource, $this->resourcesDir.'/outputs/output1.pdf'],
77+
[$multipleSources, $this->resourcesDir.'/outputs/output2.pdf'],
78+
];
79+
}
80+
4781
public function testResizeImage(): void
4882
{
4983
$command = new Command(IMAGEMAGICK_DIR);

Tests/Resources/dabug.png

161 KB
Loading

src/Command.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,18 @@ public function newCommand(?string $binary = null): self
177177
/**
178178
* @see https://imagemagick.org/script/convert.php
179179
*/
180-
public function convert(string $sourceFile, bool $checkIfFileExists = true): self
180+
public function convert($sourceFiles, bool $checkIfFileExists = true): self
181181
{
182-
return $this->newCommand('convert')->file($sourceFile, $checkIfFileExists);
182+
if (!is_array($sourceFiles)) {
183+
$sourceFiles = [$sourceFiles];
184+
}
185+
186+
$this->newCommand('convert');
187+
foreach ($sourceFiles as $sourceFile) {
188+
$this->file($sourceFile, $checkIfFileExists);
189+
}
190+
191+
return $this;
183192
}
184193

185194
/**

0 commit comments

Comments
 (0)