1. Go to this page and download the library: Download expstudio/laraclip 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/ */
expstudio / laraclip example snippets
'Expstudio\LaraClip\LaraClipServiceProvider'
use Expstudio\LaraClip\LaraClip;
class User extends LaraClip {
public function __construct(array $attributes = array()) {
$this->hasAttachedFile('image', array(
'styles' => array(
'large' => '450x450#',
'thumb' => '100x100#'
)
));
parent::__construct($attributes);
}
}
public function store()
{
// Create a new user, assigning the uploaded file field ('named avatar in the form')
// to the 'avatar' property of the user model.
$user = User::create(['avatar' => Input::file('avatar')]);
}
'styles' => array(
'watermarked' => function($file, $imagine) {
$watermark = $imagine->open('/path/to/images/watermark.png'); // Create an instance of ImageInterface for the watermark image.
$image = $imagine->open($file->getRealPath()); // Create an instance of ImageInterface for the uploaded image.
$size = $image->getSize(); // Get the size of the uploaded image.
$watermarkSize = $watermark->getSize(); // Get the size of the watermark image.
// Calculate the placement of the watermark (we're aiming for the bottom right corner here).
$bottomRight = new Imagine\Image\Point($size->getWidth() - $watermarkSize->getWidth(), $size->getHeight() - $watermarkSize->getHeight());
// Paste the watermark onto the image.
$image->paste($watermark, $bottomRight);
// Return the Imagine\Image\ImageInterface instance.
return $image;
}
)
// A user has many profile pictures.
public function profilePictures(){
return $this->hasMany('ProfilePicture');
}
public function __construct(array $attributes = array()) {
// Profile pictures have an attached file (we'll call it photo).
$this->hasAttachedFile('photo', array(
'styles' => array(
'thumbnail' => '100x100#'
)
));
parent::__construct($attributes);
}
// A profile picture belongs to a user.
public function user(){
return $this->belongsTo('User');
}
public function store()
{
// Create the new user
$user = new User(Input::get());
$user->save();
// Loop through each of the uploaded files:
// 1. Create a new ProfilePicture instance.
// 2. Attach the file to the new instance (laraclip will process it once it's saved).
// 3. Attach the ProfilePicture instance to the user and save it.
foreach(Input::file('photos') as $photo)
{
$profilePicture = new ProfilePicture(); // (1)
$profilePicture->photo = $photo; // (2)
$user->profilePictures()->save($profilePicture); // (3)
}
}
// Remove all of the attachment's uploaded files and empty the attacment attributes on the model:
$profilePicture->photo->destroy();
// For finer grained control, you can remove thumbnail files only (attachment attributes in the model will not be emptied).
$profilePicture->photo->destroy(['thumbnail']);
// Programmatically reprocess an attachment's uploaded images:
$profilePicture->photo->reprocess();