pagewiser/idn-nette
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');
}
pagewiser/idn-nette 适用场景与选型建议
pagewiser/idn-nette 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「images」 「cdn」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pagewiser/idn-nette 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pagewiser/idn-nette 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pagewiser/idn-nette 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Convert and serve jpeg/png to webp with PHP (if at all possible)
Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP
Automatically rewrites the URLs of media and assets to use a CDN
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-12-26