arisharyanto / laracrop
创建裁剪图片功能的库
1.0.3
2018-01-03 15:45 UTC
Requires
- php: ~5.5|~7.0
This package is not auto-updated.
Last update: 2024-09-29 05:01:30 UTC
README
使用 jCrop 简单裁剪 Laravel 图片
如何安装
- 在您的终端运行
$ cd yourprojectdirectory
$ composer require arisharyanto/laracrop
- 在 config/app.php 中添加服务提供者
Arisharyanto\Laracrop\LaracropServiceProvider::class,
- 在终端运行此命令
$ php artisan vendor:publish --provider="Arisharyanto\Laracrop\LaracropServiceProvider"
- 在
config/laracrop.php中设置默认配置
# IMPORTANT! the config which is mark with double asterisk (**) you must change this to something unique after install laracrop because security risk
'route_prefix' => "laracrop", # **route prefix to ajax url
'upload_url' => "upload/image", # **route url to ajax upload url route_prefix/upload_url
'path_upload' => "public/filetmp", # **where you put file upload
'image_url' => "filetmp", # **please note you must change this with same url from path_upload exclude "public"
'aspectratio' => "1", # 1 to set ratio same with width and height of image or
# you can set with custom ratio like 3/1 or 2/1 whatever you want
# set 0 to free crop
'minsize' => "[200, 200]", # Minimum selection size [ width, height ] set 0 to remove min size
'maxsize' => "[500, 500]", # Maxium selection size [ width, height ] set 0 to remove max size
'bgcolor' => "black", # Color value for background shading
'bgopacity' => "0.6" # Opacity value for background shading
'boxwidth' => "600", # set image width
'boxheight' => "600" # set image heigth
如何使用
在您的 blade 视图中
# adding laracrop css set true to embed bootstrap css or set empty the parameters to not embeded
@laracropCss(true)
# you can add custom setting for some croping
@laracrop(name=desktop | aspectratio=1 | minsize=[300, 300] | bgcolor=black | bgopacity=0.7)
# or you just write with name parameters like this to set default config
@laracrop(mobile)
# NOTE: name is required
# adding laracrop JS set true to embed jQuery or set empty the parameters to not embeded
@laracropJs(true)
在您的控制器中添加 use Arisharyanto\Laracrop\Laracrop
并在您的函数中添加以下内容
# call this function with parameter $request->input('mobile') from view @laracrop(mobile) will return filename to store in database
$getName = Laracrop::cropImage($request->input('desktop'));
#call this function at the end of your function to clean temporary file when your uploading image to crop
Laracrop::cleanCropTemp();
致谢
许可证
查看许可证https://github.com/Aris-haryanto/Laracrop/blob/master/LICENSE
作者
Aris Haryanto 访问我的网站 https://arindasoft.wordpress.com/
