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
90bad245
Commit
90bad245
authored
Oct 29, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare a croppy class
parent
c58bdbdc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
2 deletions
+147
-2
thumbnails.php
Config/thumbnails.php
+10
-0
Croppy.php
Croppy/Croppy.php
+70
-0
CroppyServiceProvider.php
Croppy/CroppyServiceProvider.php
+34
-0
MediaController.php
Http/Controllers/Admin/MediaController.php
+8
-1
CroppyTest.php
Tests/CroppyTest.php
+23
-0
module.json
module.json
+2
-1
No files found.
Config/thumbnails.php
0 → 100644
View file @
90bad245
<?php
return
[
'smallThumb'
=>
[
'crop'
=>
[
'width'
=>
'200'
,
'height'
=>
'250'
]
]
];
Croppy/Croppy.php
0 → 100644
View file @
90bad245
<?php
namespace
Modules\Media\Croppy
;
use
Illuminate\Contracts\Config\Repository
;
use
Illuminate\Contracts\Filesystem\Filesystem
;
use
Illuminate\Filesystem\FileNotFoundException
;
use
Illuminate\Support\Facades\App
;
use
Intervention\Image\Image
;
class
Croppy
{
/**
* @var Image
*/
private
$image
;
/**
* @var Filesystem
*/
private
$finder
;
/**
* @var Repository
*/
private
$config
;
public
function
__construct
(
Filesystem
$finder
,
Repository
$config
)
{
$this
->
image
=
App
::
make
(
'Intervention\Image\ImageManager'
);
$this
->
finder
=
App
::
make
(
'Illuminate\Filesystem\Filesystem'
);
$this
->
config
=
$config
;
}
public
function
image
(
$path
,
$thumbnail
)
{
$filename
=
'/assets/media/'
.
$this
->
newFilename
(
$path
,
$thumbnail
);
try
{
$this
->
finder
->
get
(
public_path
()
.
$filename
);
return
$filename
;
}
catch
(
FileNotFoundException
$e
)
{
}
$image
=
$this
->
makeImage
(
$path
,
$thumbnail
);
$this
->
finder
->
put
(
public_path
()
.
$filename
,
$image
);
return
$filename
;
}
/**
* Prepend the thumbnail name to filename
* @param $path
* @param $thumbnail
* @return mixed|string
*/
private
function
newFilename
(
$path
,
$thumbnail
)
{
$filename
=
pathinfo
(
$path
,
PATHINFO_FILENAME
);
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
));
}
}
Croppy/CroppyServiceProvider.php
0 → 100644
View file @
90bad245
<?php
namespace
Modules\Media\Croppy
;
use
Illuminate\Support\ServiceProvider
;
class
CroppyServiceProvider
extends
ServiceProvider
{
public
function
boot
()
{
$this
->
package
(
'nwidart/croppy'
);
}
/**
* Register the service provider.
*
* @return void
*/
public
function
register
()
{
$app
=
$this
->
app
;
$app
[
'croppy'
]
=
$app
->
share
(
function
(
$app
)
{
new
Croppy
(
$app
[
'filesystem.disk'
],
$app
[
'config'
]);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public
function
provides
()
{
return
[
'croppy'
];
}
}
Http/Controllers/Admin/MediaController.php
View file @
90bad245
...
...
@@ -4,6 +4,7 @@ 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\Repositories\FileRepository
;
...
...
@@ -14,10 +15,15 @@ class MediaController extends AdminBaseController
* @var FileRepository
*/
private
$file
;
/**
* @var Croppy
*/
private
$croppy
;
public
function
__construct
(
FileRepository
$file
)
public
function
__construct
(
FileRepository
$file
,
Croppy
$croppy
)
{
$this
->
file
=
$file
;
$this
->
croppy
=
$croppy
;
}
/**
...
...
@@ -67,6 +73,7 @@ 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'
));
return
View
::
make
(
'media::admin.edit'
,
compact
(
'file'
));
}
...
...
Tests/CroppyTest.php
0 → 100644
View file @
90bad245
<?php
namespace
Modules\Media\Tests
;
use
Modules\Core\Tests\BaseTestCase
;
use
Modules\Media\Croppy\Croppy
;
class
CroppyTest
extends
BaseTestCase
{
/**
* @var Croppy
*/
protected
$croppy
;
public
function
setUp
()
{
$this
->
refreshApplication
();
$this
->
croppy
=
new
Croppy
(
$this
->
app
[
'filesystem.disk'
],
$this
->
app
[
'config'
]);
}
/** @test */
public
function
it_should_return_an_extension
()
{
}
}
module.json
View file @
90bad245
...
...
@@ -10,6 +10,7 @@
},
"providers"
:
[
"Modules
\\
Media
\\
Providers
\\
MediaServiceProvider"
,
"Modules
\\
Media
\\
Providers
\\
RouteServiceProvider"
"Modules
\\
Media
\\
Providers
\\
RouteServiceProvider"
,
"Modules
\\
Media
\\
Croppy
\\
CroppyServiceProvider"
]
}
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