vintage/yii2-tinify
Composer 安装命令:
composer require vintage/yii2-tinify
包简介
Facade of Tinify API for Yii2 Framework
README 文档
README
Tinify API
Facade of Tinify API for Yii2 Framework. This extension allows you to resize and compress images without loss of quality. For more information you can read official API documentation for PHP.
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require vintage/yii2-tinify
or add
"vintage/yii2-tinify": "~2.1"
to the require section of your composer.json.
Usage
Component
- Configure API token in app params with key
tinify-api-tokenor inUploadedFilecomponent - Use
\vintage\tinify\UploadedFileinstead of\yii\web\UploadedFile
If you need to save some metadata, for example location, you can configure saveMetadata option like follow
use vintage\tinify\UploadedFile; $file = UploadedFile::getInstance($model, 'image'); $file->saveMetadata = UploadedFile::METADATA_LOCATION; // or more items $file->saveMetadata = [UploadedFile::METADATA_LOCATION, UploadedFile::METADATA_CREATION];
Upload files to AWS S3 storage
- Configure AWS S3 service in
config/params-local.php
use vintage\tinify\UploadedFileS3; return [ // ... UploadedFileS3::PARAM_KEY_AWS_ACCESS_KEY_ID => '', UploadedFileS3::PARAM_KEY_AWS_SECRET_ACCESS_KEY => '', UploadedFileS3::PARAM_KEY_S3_REGION => '', UploadedFileS3::PARAM_KEY_S3_BUCKET => '', ];
- Use
\vintage\tinify\UploadedFileS3insead of\vintage\tinify\UploadedFile - Provide region and bucket name in methods calls
$file = UploadedFile::getInstance($model, 'image')->saveAs('image.jpg');
also you can override region and bucket
$file = UploadedFile::getInstance($model, 'image') ->setRegion('us-west-1') ->setPath('images-bucket/uploads') // path must be provided without slash in the end ->saveAs('image.jpg');
Resizing
You can resize uploaded file
$file = \vintage\tinify\UploadedFile::getInstance($model, 'image'); $file->resize() // creates \vintage\tinify\components\TinifyResize object ->fit() // resize algorithm, also you can use scale() and cover() ->width(600) // set image width ->height(400) // set image height ->process(); // resize image $file->saveAs('@webroot/uploads');
or resize existing image
(new \vintage\tinify\components\TinifyResize('@webroot/uploads/image.jpg')) ->scale() ->width(600) ->process();
CLI
- Configure console controller in
console/config/main.php
'controllerMap' => [ // ... 'tinify' => \vintage\tinify\cli\TinifyController::class, ],
-
Run in console
./yii tinify/<command>Command Description $ ./yii tinify/test-connect [api-token]Test connection to API $ ./yii tinify/compress '/path/to/src.jpg' '/path/to/dest.jpg'Compress image $ ./yii tinify/compress-catalog '/path/to/catalog'Compress all images in catalog $ ./yii tinify/countDisplay compression images count
Tests
You can run tests with composer command
$ composer test
or using following command
$ codecept build && codecept run
Licence
This project is released under the terms of the BSD-3-Clause license.
vintage/yii2-tinify 适用场景与选型建议
vintage/yii2-tinify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.27k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「compress」 「images」 「resize」 「component」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vintage/yii2-tinify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vintage/yii2-tinify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vintage/yii2-tinify 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
OriginPHP Html
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 9.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-08-07