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
bea53b77
Commit
bea53b77
authored
Oct 30, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a factory for image manipulations
parent
90bad245
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
131 additions
and
33 deletions
+131
-33
thumbnails.php
Config/thumbnails.php
+2
-1
MediaController.php
Http/Controllers/Admin/MediaController.php
+7
-6
ImageFactoryInterface.php
Image/ImageFactoryInterface.php
+11
-0
ImageHandlerInterface.php
Image/ImageHandlerInterface.php
+12
-0
ImageServiceProvider.php
Image/ImageServiceProvider.php
+39
-0
Imagy.php
Image/Imagy.php
+20
-25
InterventionFactory.php
Image/Intervention/InterventionFactory.php
+17
-0
BaseManipulation.php
Image/Intervention/Manipulations/BaseManipulation.php
+5
-0
Crop.php
Image/Intervention/Manipulations/Crop.php
+17
-0
module.json
module.json
+1
-1
No files found.
Config/thumbnails.php
View file @
bea53b77
...
...
@@ -5,6 +5,7 @@ return [
'crop'
=>
[
'width'
=>
'200'
,
'height'
=>
'250'
]
],
// 'blur' => '15'
]
];
Http/Controllers/Admin/MediaController.php
View file @
bea53b77
...
...
@@ -4,9 +4,9 @@ use Illuminate\Support\Facades\Redirect;
use
Illuminate\Support\Facades\View
;
use
Laracasts\Flash\Flash
;
use
Modules\Core\Http\Controllers\Admin\AdminBaseController
;
use
Modules\Media\Croppy\Croppy
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Http\Requests\UpdateMediaRequest
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Repositories\FileRepository
;
class
MediaController
extends
AdminBaseController
...
...
@@ -16,14 +16,14 @@ class MediaController extends AdminBaseController
*/
private
$file
;
/**
* @var
Cropp
y
* @var
Imag
y
*/
private
$
cropp
y
;
private
$
imag
y
;
public
function
__construct
(
FileRepository
$file
,
Croppy
$cropp
y
)
public
function
__construct
(
FileRepository
$file
,
Imagy
$imag
y
)
{
$this
->
file
=
$file
;
$this
->
croppy
=
$cropp
y
;
$this
->
imagy
=
$imag
y
;
}
/**
...
...
@@ -73,7 +73,8 @@ class MediaController extends AdminBaseController
*/
public
function
edit
(
File
$file
)
{
dd
(
$this
->
croppy
->
image
(
'/assets/media/screen-shot-2014-10-25-at-44939-pm.png'
,
'smallThumb'
));
dd
(
$this
->
imagy
->
get
(
'/assets/media/screen-shot-2014-10-25-at-44939-pm.png'
,
'smallThumb'
));
//dd($this->croppy->image('/assets/media/screen-shot-2014-10-25-at-44939-pm.png', 'smallThumb'));
return
View
::
make
(
'media::admin.edit'
,
compact
(
'file'
));
}
...
...
Image/ImageFactoryInterface.php
0 → 100644
View file @
bea53b77
<?php
namespace
Modules\Media\Image
;
interface
ImageFactoryInterface
{
/**
* Return a new Manipulation class
* @param array $manipulation
* @return \Modules\Media\Image\ImageHandlerInterface
*/
public
function
make
(
$manipulation
);
}
Image/ImageHandlerInterface.php
0 → 100644
View file @
bea53b77
<?php
namespace
Modules\Media\Image
;
interface
ImageHandlerInterface
{
/**
* Handle the image manipulation request
* @param \Intervention\Image\Image $image
* @param array $options
* @return \Intervention\Image\Image
*/
public
function
handle
(
$image
,
$options
);
}
Croppy/Croppy
ServiceProvider.php
→
Image/Image
ServiceProvider.php
View file @
bea53b77
<?php
namespace
Modules\Media\
Croppy
;
<?php
namespace
Modules\Media\
Image
;
use
Illuminate\Support\ServiceProvider
;
use
Modules\Media\Image\Intervention\InterventionFactory
;
class
Croppy
ServiceProvider
extends
ServiceProvider
class
Image
ServiceProvider
extends
ServiceProvider
{
public
function
boot
()
{
$this
->
package
(
'nwidart/
cropp
y'
);
$this
->
package
(
'nwidart/
imag
y'
);
}
/**
...
...
@@ -16,9 +17,13 @@ class CroppyServiceProvider extends ServiceProvider
*/
public
function
register
()
{
$app
=
$this
->
app
;
$app
[
'croppy'
]
=
$app
->
share
(
function
(
$app
)
{
new
Croppy
(
$app
[
'filesystem.disk'
],
$app
[
'config'
]);
$this
->
app
->
bind
(
'Modules\Media\Image\ImageFactoryInterface'
,
'Modules\Media\Image\Intervention\InterventionFactory'
);
$app
[
'imagy'
]
=
$this
->
app
->
share
(
function
(
$app
)
{
return
new
Imagy
(
$app
[
'config'
],
new
InterventionFactory
);
});
}
...
...
@@ -29,6 +34,6 @@ class CroppyServiceProvider extends ServiceProvider
*/
public
function
provides
()
{
return
[
'
cropp
y'
];
return
[
'
imag
y'
];
}
}
Croppy/Cropp
y.php
→
Image/Imag
y.php
View file @
bea53b77
<?php
namespace
Modules\Media\
Croppy
;
<?php
namespace
Modules\Media\
Image
;
use
Illuminate\Contracts\Config\Repository
;
use
Illuminate\Contracts\Filesystem\Filesystem
;
use
Illuminate\Filesystem\FileNotFoundException
;
use
Illuminate\Support\Facades\App
;
use
I
ntervention\Image\Image
;
use
I
lluminate\Contracts\Config\Repository
;
class
Cropp
y
class
Imag
y
{
/**
* @var Image
* @var
\Intervention\Image\
Image
*/
private
$image
;
/**
* @var Filesystem
* @var
\Illuminate\Filesystem\
Filesystem
*/
private
$finder
;
/**
* @var Repository
* @var
\Illuminate\Contracts\Config\
Repository
*/
private
$config
;
/**
* @var ImageFactoryInterface
*/
private
$imageFactory
;
public
function
__construct
(
Filesystem
$finder
,
Repository
$config
)
public
function
__construct
(
Repository
$config
,
ImageFactoryInterface
$imageFactory
)
{
$this
->
image
=
App
::
make
(
'Intervention\Image\ImageManager'
);
$this
->
finder
=
App
::
make
(
'Illuminate\Filesystem\Filesystem'
);
$this
->
config
=
$config
;
$this
->
imageFactory
=
$imageFactory
;
}
public
function
image
(
$path
,
$thumbnail
)
public
function
get
(
$path
,
$thumbnail
)
{
$filename
=
'/assets/media/'
.
$this
->
newFilename
(
$path
,
$thumbnail
);
try
{
$this
->
finder
->
get
(
public_path
()
.
$filename
);
return
$filename
;
}
catch
(
FileNotFoundException
$e
)
{
}
$image
=
$this
->
image
->
make
(
public_path
()
.
$path
);
$image
=
$this
->
makeImage
(
$path
,
$thumbnail
);
foreach
(
$this
->
config
->
get
(
"media::thumbnails.
{
$thumbnail
}
"
)
as
$manipulation
=>
$options
)
{
$image
=
$this
->
imageFactory
->
make
(
$manipulation
)
->
handle
(
$image
,
$options
);
}
$this
->
finder
->
put
(
public_path
()
.
$filename
,
$image
);
$image
=
$image
->
encode
(
pathinfo
(
$path
,
PATHINFO_EXTENSION
)
);
return
$filename
;
$this
->
finder
->
put
(
public_path
()
.
$filename
,
$image
);
}
}
/**
...
...
@@ -56,15 +62,4 @@ class Croppy
return
$filename
.
'_'
.
$thumbnail
.
'.'
.
pathinfo
(
$path
,
PATHINFO_EXTENSION
);
}
private
function
makeImage
(
$path
,
$thumbnail
)
{
$thumbnailActions
=
$this
->
config
->
get
(
"media::thumbnails.
{
$thumbnail
}
"
);
$image
=
$this
->
image
->
make
(
public_path
()
.
$path
);
return
$image
->
crop
(
$thumbnailActions
[
'crop'
][
'width'
],
$thumbnailActions
[
'crop'
][
'height'
])
->
encode
(
pathinfo
(
$path
,
PATHINFO_EXTENSION
));
}
}
Image/Intervention/InterventionFactory.php
0 → 100644
View file @
bea53b77
<?php
namespace
Modules\Media\Image\Intervention
;
use
Modules\Media\Image\ImageFactoryInterface
;
class
InterventionFactory
implements
ImageFactoryInterface
{
/**
* @param $manipulation
* @return mixed
*/
public
function
make
(
$manipulation
)
{
$class
=
'Modules\\Media\\Image\\Intervention\\Manipulations\\'
.
ucfirst
(
$manipulation
);
return
new
$class
;
}
}
Image/Intervention/Manipulations/BaseManipulation.php
0 → 100644
View file @
bea53b77
<?php
namespace
Modules\Media\Image\Intervention\Manipulations
;
abstract
class
BaseManipulation
{
}
Image/Intervention/Manipulations/Crop.php
0 → 100644
View file @
bea53b77
<?php
namespace
Modules\Media\Image\Intervention\Manipulations
;
use
Modules\Media\Image\ImageHandlerInterface
;
class
Crop
extends
BaseManipulation
implements
ImageHandlerInterface
{
/**
* Handle the image manipulation request
* @param \Intervention\Image\Image $image
* @param array $options
* @return mixed
*/
public
function
handle
(
$image
,
$options
)
{
return
$image
->
crop
(
$options
[
'width'
],
$options
[
'height'
]);
}
}
module.json
View file @
bea53b77
...
...
@@ -11,6 +11,6 @@
"providers"
:
[
"Modules
\\
Media
\\
Providers
\\
MediaServiceProvider"
,
"Modules
\\
Media
\\
Providers
\\
RouteServiceProvider"
,
"Modules
\\
Media
\\
Croppy
\\
Croppy
ServiceProvider"
"Modules
\\
Media
\\
Image
\\
Image
ServiceProvider"
]
}
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