anakadote/laravel-5-image-manager
Composer 安装命令:
composer require anakadote/laravel-5-image-manager
包简介
Image resizing and cropping package for Laravel.
README 文档
README
Deprecated: This package is now deprecated in favor of https://github.com/anakadote/ImageManager for further development
Image Resizing and Cropping Package for Laravel
This Laravel package provides a convenient way of resizing and cropping images.
Begin by installing this package through Composer. Edit your project's composer.json file to require anakadote/laravel-5-image-manager.
"require": {
"anakadote/laravel-5-image-manager": "dev-master"
}
Next, update Composer from the Terminal:
composer update
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
-
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/laravel-5-image-manager 适用场景与选型建议
anakadote/laravel-5-image-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.9k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2015 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「images」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anakadote/laravel-5-image-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anakadote/laravel-5-image-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anakadote/laravel-5-image-manager 相关的其它包
同方向 / 同关键字的高下载量 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
Yii2 prettyPhoto image galary widget uses Lightbox view control jquery.prettyphoto.js
统计信息
- 总下载量: 8.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-18