just/thumbnailbundle
Composer 安装命令:
composer require just/thumbnailbundle
包简介
A Symfony bundle that creates Thumbnails on the fly using the GD library
关键字:
README 文档
README
Overview
This is a bundle for the Symfony2, Symfony3 and Symfony4 framework that creates Thumbnails on first demand. The thumbnails then are stored using the Symfony cache system. It creates a thumbnail of a image in the given size and stores it in cache for the next calls, until the image changes. The bundle has a new face-detection feature to avoid cut off of faces.
License
This bundle is released under the MIT license
Installation
Step1: Using Composer
Add the following line to your composer.json require block:
// composer.json
{
// ...
require: {
// ...
"just/thumbnailbundle": "~2.0"
}
}
Then, you can install the new dependencies by running Composer's update
command from the directory where your composer.json file is located:
$ php composer.phar update
Step 2: Register the Bundle
Modify your AppKernel with the following line:
<?php // in AppKernel::registerBundles() $bundles = array( // ... new Just\ThumbnailBundle\JustThumbnailBundle(), // ... );
Step 3: Configure the bundle
# app/config/config.yml just_thumbnail: imagesrootdir: "/path/to/the/images/root/dir/on/server/" placeholder: "/path/to/a/placeholder/image.jpg" expiretime: 86400
All parameters are optional. The default imagesrootdir is the Symfony web-directory. The placeholder-Image will be showen if the original image is not readable or not found. If the placeholder parameter is not set then the Controller will return a "404 Not found" message. "expiretime" is maximum age of a thumbnail in cache in seconds. After this time the thumbnail will be regenerated. Default value is 86400 (one day).
The thumbnail is stored in cache by a key that is generated using the image-name, the maxx-parameter, the maxy-parameter, the mode-parameter and the creationtime. If one of those parameters changes than the thumbnail will be regenerated.
If not already done, you have to define a cache service
# app/config/config.yml services: cache: class: Doctrine\Common\Cache\ApcuCache
Note:
The JustThumbnailBundle needs to have gd.jpeg_ignore_warning set to "1". Set gd.jpeg_ignore_warning to "1" in your php.ini, and restart your webserver.
Step 4: Import JustThumbnailBundle routing file
In YAML:
# app/config/routing.yml just_thumbnail_bundle: resource: "@JustThumbnailBundle/Resources/config/routing.yml"
Or if you prefer XML:
<!-- app/config/routing.xml --> <import resource="@JustThumbnailBundle/Resources/config/routing.yml"/>
Usage:
The thumbnail will be generated just in time when the url is called:
/thumbnails/{mode}/{maxx}x{maxy}/{img}
/thumbnails/{mode}/{maxx}x/{img}
/thumbnails/{mode}/x{maxy}/{img}
Parameter "mode"
This parameter can be set to "normal", "crop", "stretch" and "max".
- normal: Sets the image to the maximum height or width, without changing the width/height proportion;
- crop: The image will be cropped exactly to the given height and width without changing the width/height proportion;
- stretch: Sets the image to the maximum height or width, the width/height proportion changes.
- max: Sets the image to the maximum height or width, without changing the width/height proportion;
Parameter maxx and maxy
"maxx" is the maximum width and "maxy" the maximun height of the generated thumbnail.
Placeholder
You can overwrite the placeholder-file-config by adding a "placeholder"-Parameter to the url. Example: www.yourdomain.tld/thumbnails/stretch/800x225/path/to/image?placeholder=new_placeholder_image.jpg
Parameter "center"
This parameter can be set to "", "auto", or "[int],[int]". Default is "". This parameter can be used to define a center point of a image that should be always visible in crop mode. This is to avoid that highlights of the image are cut off. If set to "auto", the script will try to detect a face in the image. If found, the center will be set to the center of the detected face. So the face should not be cut off.
Twig Helper
You can use the twig helper to generate the URL :
{{thumbnail({'img':'path/to/image','maxx':320,'maxy':240,'mode':'stretch'})}}
will generate something like:
/thumbnails/stretch/300x240/path/to/image
just/thumbnailbundle 适用场景与选型建议
just/thumbnailbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.55k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「bundle」 「thumbnail」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 just/thumbnailbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 just/thumbnailbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 just/thumbnailbundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
A PHP library for fetching thumbnails from a URL
DMS Meetup API Bundle, enables Meetup API clients in services
A Gokaru storage & thumbnail server PHP client
统计信息
- 总下载量: 1.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-20