Commit 44a4b886 authored by Nicolas Widart's avatar Nicolas Widart

Adding checks if the media is an image

parent b39090b8
...@@ -21,6 +21,16 @@ class Imagy ...@@ -21,6 +21,16 @@ class Imagy
*/ */
private $manager; private $manager;
/**
* All the different images types where thumbnails should be created
* @var array
*/
private $imageExtensions = ['jpg','png','jpeg','gif'];
/**
* @param ImageFactoryInterface $imageFactory
* @param ThumbnailsManager $manager
*/
public function __construct(ImageFactoryInterface $imageFactory, ThumbnailsManager $manager) public function __construct(ImageFactoryInterface $imageFactory, ThumbnailsManager $manager)
{ {
$this->image = App::make('Intervention\Image\ImageManager'); $this->image = App::make('Intervention\Image\ImageManager');
...@@ -38,6 +48,8 @@ class Imagy ...@@ -38,6 +48,8 @@ class Imagy
*/ */
public function get($path, $thumbnail, $forceCreate = false) public function get($path, $thumbnail, $forceCreate = false)
{ {
if (!$this->isImage($path)) return;
$filename = '/assets/media/' . $this->newFilename($path, $thumbnail); $filename = '/assets/media/' . $this->newFilename($path, $thumbnail);
if ($this->returnCreatedFile($filename, $forceCreate)) { if ($this->returnCreatedFile($filename, $forceCreate)) {
...@@ -129,4 +141,14 @@ class Imagy ...@@ -129,4 +141,14 @@ class Imagy
$this->writeImage($filename, $image); $this->writeImage($filename, $image);
} }
/**
* Check if the given path is en image
* @param string $path
* @return bool
*/
private function isImage($path)
{
return in_array(pathinfo($path, PATHINFO_EXTENSION), $this->imageExtensions);
}
} }
...@@ -29,7 +29,9 @@ class ImagyTest extends BaseTestCase ...@@ -29,7 +29,9 @@ class ImagyTest extends BaseTestCase
/** @test */ /** @test */
public function it_should_create_a_file() public function it_should_create_a_file()
{ {
$this->finder->delete(public_path() . '/assets/media/google-map_smallThumb.png'); if ($this->finder->isFile(public_path() . '/assets/media/google-map_smallThumb.png')) {
$this->finder->delete(public_path() . '/assets/media/google-map_smallThumb.png');
}
$this->imagy->get('/assets/media/google-map.png', 'smallThumb', true); $this->imagy->get('/assets/media/google-map.png', 'smallThumb', true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment