定制 anakadote/laravel-5-image-manager 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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:

  1. File Name (string) The fully qualified name of image file. The file must reside in your app's public directory. You'll need to grant write access by the web server to the public directory and its children.

  2. Width (integer) Desired width of the image.

  3. Height (integer) Desired height of the image.

  4. Output Mode (string) The output mode. Options are:

  5. crop

  6. fit - Fit while maintaining aspect ratio.

  7. fit-x - Fit to the given width while maintaining aspect ratio.

  8. fit-y - Fit to the given height while maintaining aspect ratio.

  9. Image Quality - (integer, 0 - 100) Default value is 90.

  10. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 anakadote/laravel-5-image-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 15
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-18