2017 © Pedro Peláez
 

library simple-image-storage

Simple image storage for Nette

image

inteve/simple-image-storage

Simple image storage for Nette

  • Sunday, June 24, 2018
  • by janpecha
  • Repository
  • 1 Watchers
  • 2 Stars
  • 939 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 3 % Grown

The README.md

Simple Image Storage

Image storage for Nette., (*1)

Become a Patron! Buy me a coffee, (*2)

Installation

Download a latest package or use Composer:, (*3)

composer require inteve/simple-image-storage

Library requires PHP 5.6.0 or later., (*4)

Usage

``` php use Inteve\SimpleImageStorage\ImageStorage;, (*5)



### Register in config ``` yaml parameters: imageStorage: directory: %wwwDir% publicDirectory: @httpRequest::getUrl()::getBaseUrl() storageName: images # optional services: - Inteve\SimpleImageStorage\ImageStorage(%imageStorage.directory%, %imageStorage.publicDirectory%, %imageStorage.storageName%)

Store image

``` php <?php $image = $imageStorage->upload($fileUpload); // $image = 'image-name.jpg', (*6)

$avatar = $imageStorage->upload($fileUpload, 'upload/avatars'); // $avatar = 'upload/avatars/image-name.jpg';, (*7)



### Delete image ``` php <?php $imageStorage->delete('upload/avatar/image-name.jpg');

Get original path

``` php <?php $path = $imageStorage->getRealPath('upload/avatar/image-name.jpg');, (*8)



### Get original public path ``` php <?php $path = $imageStorage->getPublicPath('upload/avatar/image-name.jpg');

Thumbnails

``` php <?php $path = $imageStorage->thumbnail($file, $width, $height, $flags = NULL, $quality = NULL); $path = $imageStorage->thumbnail('upload/avatar/image-name.jpg', 512, 256);, (*9)


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;, (*10)

protected function beforeRender()
{
    parent::beforeRender();
    $this->template->img = $this->imageStorage;
}

}, (*11)


``` smarty <img src="{$img->thumbnail($avatar, 512, 256)}"> <img src="{$img->thumbnail($avatar, 512, 256, $img::SHRINK_ONLY)}"> <img src="{$img->thumbnail($avatar, 512, 256, $img::STRETCH)}"> <img src="{$img->thumbnail($avatar, 512, 256, $img::FILL)}"> <img src="{$img->thumbnail($avatar, 512, 256, $img::EXACT)}">

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/, (*12)

The Versions

24/06 2018

dev-master

9999999-dev

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

08/01 2018

v2.0.0

2.0.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

18/12 2017

v1.6.0

1.6.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

11/09 2017

v1.5.0

1.5.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

12/10 2016

v1.4.0

1.4.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

13/09 2016

v1.3.0

1.3.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

11/07 2016

v1.2.0

1.2.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

04/07 2016

v1.1.1

1.1.1.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

24/06 2016

v1.1.0

1.1.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires

 

05/03 2016

v1.0.0

1.0.0.0

Simple image storage for Nette

  Sources   Download

BSD-3-Clause

The Requires