anakadote/image-manager
Composer 安装命令:
composer require anakadote/image-manager
包简介
Image resizing and cropping package for Laravel.
README 文档
README
This Laravel package provides a convenient way of resizing and cropping images.
Begin by installing this package through Composer via the terminal.
composer require anakadote/image-manager
Next, add the service provider. Open config/app.php and add a new item to the providers array.
Anakadote\ImageManager\ImageManagerServiceProvider::class
The final step is to use artisan to move the package assets to the public directory, also from the Terminal:
php artisan vendor:publish --provider="Anakadote\ImageManager\ImageManagerServiceProvider"
Usage
This package is accessible via a Laravel Facade so to use simply call its methods on the Facade "ImageManager".
getImagePath($filename, $width, $height, $mode, $quality = 90)
Example 1: Resize or crop an image and get the newly generated image's web path.
<img src="{{ ImageManager::getImagePath(public_path() . '/img/' . $image->filename, 250, 200, 'crop') }}" alt="">
Example 2: Use an HTML picture element to display a webp version of the image, if supported by the browser.
<picture> <source srcset="{{ ImageManager::getImagePath(public_path() . '/img/' . $image->filename, 250, 200, 'crop', 90, 'webp') }}" type="image/webp"> <img src="{{ ImageManager::getImagePath(public_path() . '/img/' . $image->filename, 250, 200, 'crop') }}" alt=""> </picture>
The getImagePath() method has six parameters, the first four of which are required:
-
File Name (string) The fully qualified name of image file. The file must reside in your app's
publicdirectory. You'll need to grant write access by the web server to thepublicdirectory and its children. -
Width (integer) Desired width of the image.
-
Height (integer) Desired height of the image.
-
Output Mode (string) The output mode. Options are:
- crop - Crop from the vertical middle.
- crop-top - Crop from the top.
- crop-bottom - Crop from the bottom.
- fit - Fit while maintaining aspect ratio.
- fit-x - Fit to the given width while maintaining aspect ratio.
- fit-y - Fit to the given height while maintaining aspect ratio.
-
Image Quality - (integer, 0 - 100) Default value is 90.
-
Format - (string) Convert the image to the given format/extension, e.g. "webp";
getUniqueFilename($filename, $destination)
Generate a unique file name within a destination directory — uses the original file name as the basis for the new file name.
<?php $unique_filename = ImageManager::getUniqueFilename($filename, public_path() . '/img/');
The getUniqueFilename() method has two parameters: the original filename, and the destination path.
deleteImage($filename)
Delete an image including all resized and/or cropped images generated from it.
<?php ImageManager::deleteImage(public_path() . '/img/' . $image->filename);
The deleteImage() method has a single parameter which is the fully qualified name of the original image file. This method will recursively delete all generated images from the original image file.
anakadote/image-manager 适用场景与选型建议
anakadote/image-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.13k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image manipulation」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anakadote/image-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anakadote/image-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anakadote/image-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
On-demand image manipulation service.
Laravel package for resized.co, the on-demand image manipulation service.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Manipulate images in pure PHP
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 6.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-11