Skip to content

Commit

Permalink
Stream images when performing conversions (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack97 committed Oct 30, 2019
1 parent c47b641 commit 2a0ddea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ImageManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ public function manipulate(Media $media, array $conversions, $onlyIfMissing = tr
foreach ($conversions as $conversion) {
$path = $media->getPath($conversion);

if ($onlyIfMissing && $media->filesystem()->exists($path)) {
$filesystem = $media->filesystem();

if ($onlyIfMissing && $filesystem->exists($path)) {
continue;
}

$converter = $this->conversionRegistry->get($conversion);

$image = $converter(
$this->imageManager->make($media->getFullPath())
);
$image = $converter($this->imageManager->make(
$filesystem->readStream($media->getPath())
));

$media->filesystem()->put($path, $image->stream());
$filesystem->put($path, $image->stream());
}
}
}
1 change: 1 addition & 0 deletions tests/ImageManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function it_will_apply_registered_conversions()
$media->mime_type = 'image/png';

$filesystem = Mockery::mock(Filesystem::class);
$filesystem->shouldReceive('readStream')->andReturn('stream-data');
$filesystem->shouldReceive('path')->with($media->getPath())->andReturn('full-path');

// Assert that the converted file is saved...
Expand Down

0 comments on commit 2a0ddea

Please sign in to comment.