Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
44a4b886
Commit
44a4b886
authored
Oct 31, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding checks if the media is an image
parent
b39090b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
Imagy.php
Image/Imagy.php
+22
-0
ImagyTest.php
Tests/ImagyTest.php
+3
-1
No files found.
Image/Imagy.php
View file @
44a4b886
...
...
@@ -21,6 +21,16 @@ class Imagy
*/
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
)
{
$this
->
image
=
App
::
make
(
'Intervention\Image\ImageManager'
);
...
...
@@ -38,6 +48,8 @@ class Imagy
*/
public
function
get
(
$path
,
$thumbnail
,
$forceCreate
=
false
)
{
if
(
!
$this
->
isImage
(
$path
))
return
;
$filename
=
'/assets/media/'
.
$this
->
newFilename
(
$path
,
$thumbnail
);
if
(
$this
->
returnCreatedFile
(
$filename
,
$forceCreate
))
{
...
...
@@ -129,4 +141,14 @@ class Imagy
$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
);
}
}
Tests/ImagyTest.php
View file @
44a4b886
...
...
@@ -29,7 +29,9 @@ class ImagyTest extends BaseTestCase
/** @test */
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment