1. Go to this page and download the library: Download clapp/imagerepository 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/ */
clapp / imagerepository example snippets
use Clapp\ImageRepository\ImageRepository;
use Clapp\ImageRepository\ImageMissingOrInvalidException;
class User {
protected $profilePictureRepository = null;
public function __construct(/* ... */){
$this->profilePictureRepository = new ImageRepository('profile-pictures/');
/* ... */
}
public function getProfilePicture($width=500, $height=500)
{
try {
return $this->profilePictureRepository->get(array_get($this->attributes, 'profile_picture'), $width, $height);
}catch(ImageMissingOrInvalidException $e){
return $this->profilePictureRepository->get(resource_path('assets/images/placeholder.png'), $width, $height);
}
}
public function setProfilePictureAttribute($pictureContents){
$value = $pictureContents;
if (!empty($value)){
$value = $this->profilePictureRepository->put($value);
}
$this->attributes['profile_picture'] = $value;
}
}