定制 pagewiser/idn-nette 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pagewiser/idn-nette

最新稳定版本:v0.2

Composer 安装命令:

composer require pagewiser/idn-nette

包简介

Nette helpers and macros for IDN server

关键字:

README 文档

README

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

Install

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

Nette 2.3.x

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

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

Then you need to configure your IDN account and API class.

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

Basic usage

Image uploading

Presenter

/**
 * @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.

Image display

Latte

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

Latte macro has 4 parameters.

  • 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');
    }

统计信息

  • 总下载量: 36
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-12-26