anakadote/image-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

anakadote/image-manager

最新稳定版本:1.1.2

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:

  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:

    1. crop - Crop from the vertical middle.
    2. crop-top - Crop from the top.
    3. crop-bottom - Crop from the bottom.
    4. fit - Fit while maintaining aspect ratio.
    5. fit-x - Fit to the given width while maintaining aspect ratio.
    6. fit-y - Fit to the given height while maintaining aspect ratio.
  5. Image Quality - (integer, 0 - 100) Default value is 90.

  6. 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.

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固