PHP code example of sawastacks / kropify-laravel
1. Go to this page and download the library: Download sawastacks/kropify-laravel library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sawastacks / kropify-laravel example snippets
SawaStacks\Utils\KropifyServiceProvider::class,
Route::post('/crop',[TestController::class,'cropHandler'])->name('crop-handler');
use SawaStacks\Utils\Kropify;
public function cropHandler(Request $request){
$file = $request->file('avatar');
$path = 'uploads';
/** When you upload with move() */
$upload = Kropify::getFile($file,'userpic.png')
// ->setDisk('public') // local, public
->setPath($path)
->useMove()
->save();
/** When you upload with Storage */
$upload = Kropify::getFile($file,'userpic.png')
->setDisk('public') // local, public
->setPath($path)
// ->useMove()
->save();
/**
* GET UPLOADED IMAGE DETAILS (INFO)
* =================================
* */
// if( $upload ){ $info = $upload->getUploadedInfo(); }
// $info = $upload ? $upload->getUploadedInfo() : null;
// $info = $upload?->getUploadedInfo();
if (!$upload) { return; }
$info = $upload->getUploadedInfo();
// Store image details into DB
$im = new StoredImage();
$im->filename = $info['filename'];
$im->size = $info['size'];
$im->extension = $info['extension'];
$im->width = $info['width'];
$im->height = $info['height'];
$im->mime = $info['mime'];
$im->path = $info['path'];
$im->url = $info['url'];
$im->save();
// Returning json data
return response()->json([
'status'=>'OK',
'message'=>'Image successfully uploaded',
'data'=>$info
],201);
}