Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inteve/simple-image-storage
Simple image storage for Nette
https://github.com/inteve/simple-image-storage
image-storage nette php
Last synced: 9 days ago
JSON representation
Simple image storage for Nette
- Host: GitHub
- URL: https://github.com/inteve/simple-image-storage
- Owner: inteve
- License: other
- Created: 2016-03-04T10:37:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-24T12:31:53.000Z (over 6 years ago)
- Last Synced: 2024-11-13T20:12:46.205Z (2 months ago)
- Topics: image-storage, nette, php
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Simple Image Storage
Image storage for Nette.
## Installation
[Download a latest package](https://github.com/inteve/simple-image-storage/releases) or use [Composer](http://getcomposer.org/):
```
composer require inteve/simple-image-storage
```Library requires PHP 5.6.0 or later.
## Usage
``` php
use Inteve\SimpleImageStorage\ImageStorage;
```### Register in config
``` yaml
parameters:
imageStorage:
directory: %wwwDir%
publicDirectory: @httpRequest::getUrl()::getBaseUrl()
storageName: images # optionalservices:
- Inteve\SimpleImageStorage\ImageStorage(%imageStorage.directory%, %imageStorage.publicDirectory%, %imageStorage.storageName%)
```### Store image
``` php
upload($fileUpload);
// $image = 'image-name.jpg'$avatar = $imageStorage->upload($fileUpload, 'upload/avatars');
// $avatar = 'upload/avatars/image-name.jpg';
```### Delete image
``` php
delete('upload/avatar/image-name.jpg');
```### Get original path
``` php
getRealPath('upload/avatar/image-name.jpg');
```### Get original public path
``` php
getPublicPath('upload/avatar/image-name.jpg');
```### Thumbnails
``` php
thumbnail($file, $width, $height, $flags = NULL, $quality = NULL);
$path = $imageStorage->thumbnail('upload/avatar/image-name.jpg', 512, 256);
```It uses `Nette\Utils\Image` by default but you can provide custom thumbnail generator in constructor:
``` php
$imageStorage = new ImageStorage(..., ..., ..., function ($sourcePath, $outputPath, array $thumbnailData) {
$im = new Imagick;
$im->readImage($sourcePath);
$im->crop(...);
$im->writeImage($outputPath);
});
```* `string $sourcePath` - path to original image
* `string $outputPath` - thumbnail path
* `array $thumbnailData`
* `int|NULL width` - width of thumbnail or NULL
* `int|NULL height` - height of thumbnail or NULL
* `int|NULL quality` - quality of output image or NULL
* `int flags` - see constants ImageStorage::SHRINK_ONLY, STRETCH, FIT, FILL & EXACT### In template
``` php
class BasePresenter extends Nette\Application\UI\Presenter
{
/** @var Inteve\SimpleImageStorage\ImageStorage @inject */
public $imageStorage;protected function beforeRender()
{
parent::beforeRender();
$this->template->img = $this->imageStorage;
}
}
`````` smarty
```------------------------------
License: [New BSD License](license.md)
Author: Jan Pecha, https://www.janpecha.cz/