2017 © Pedro Peláez
 

library idn-nette

Nette helpers and macros for IDN server

image

pagewiser/idn-nette

Nette helpers and macros for IDN server

  • Tuesday, September 15, 2015
  • by marten
  • Repository
  • 1 Watchers
  • 0 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Nette IDN extension

IDN extension for Nette. Support uploading and image manipulation, adds macro for image handling into latte., (*1)

Install

To register this extension into the Nette, add the latte macro extension to your config file., (*2)

Nette 2.3.x, (*3)

extensions:
    idn: Pagewiser\Idn\Nette\Bridges\Nette\Nette23Extension

nette:
    latte:
        macros:
            - Pagewiser\Idn\Nette\IdnMacros::install

idn:
    apiHost: 'http://idnapi.pwlab.tk/'
    apiKey: 'your-api-key'
    apiSecret: 'your-api-secret'
    imageHost: '//storage.pwlab.tk/'
    lazy: TRUE
    client: 'client-name'
    profiler: TRUE
    dirAliases:
        profilePhoto: 'user/photo'

Nette 2.2.x, (*4)

services:
    nette.latteFactory:
        setup:
            - Pagewiser\Idn\Nette\IdnMacros::install(::$service->getCompiler())

Then you need to configure your IDN account and API class., (*5)

idn:
    class: Marten\NetteIdn\Api('username', 'password')

Basic usage

Image uploading

Presenter, (*6)

/**
 * @var \Pagewiser\Idn\Nette\Api $idnApi
 * @inject
 */
public $idnApi

public function formSuccess(Form $form)
{
    $values = $form->getValues();
    try
    {
        $uploadedFile = $this->idnApi->upload('photos/'.$values['id'].'.jpg', $values['file']->getTemporaryFile());

        if ($uploadedFile['status'] !== 'success')
        {
            // Rollback
        }

        // Commit
    }
    catch (\Api\Exception\ApiException $e)
    {
        $form->addError($e->getMessage());
    }
}

If you reupload image with the same name, IDN server will clear the cache for this image automatically. It's still good practice to use generated filename, because it will handle local cache in browsers., (*7)

Image display

Latte, (*8)

<img src="{idn 'photos', $job['logo'], '80x80'}">

Latte macro has 4 parameters., (*9)

  • Directory where the image is stored
  • Name of the file
  • Required size
  • Tranfromation options: ** f - Fill size with the image. Image can be bigger than provided size. ** e - Exact size of the image. Image will be stretched. ** c - Exact size of the image. Image will be cropped. ** b - Exact size of the image. Image will be resized to fit in the size, background will be added. ** a - Face detection. Image will be resized to required size, will be zoomed to face on the image.

Deleting image

    try
    {
        try
        {
            $this->idnApi->delete('photos/', $photoName);
        }
        catch (\Pagewiser\Idn\Client\FileNotFoundException $ex)
        {
            // File not found, was already deleted?
        }
    }
    catch (\Pagewiser\Idn\Client\OperationException $ex)
    {
        $this->flashMessage($ex->getMessage(), 'warning');
    }

The Versions

15/09 2015

dev-master

9999999-dev

Nette helpers and macros for IDN server

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

cdn images

15/09 2015

v0.2

0.2.0.0

Nette helpers and macros for IDN server

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

cdn images