modularavel/imgenerator 问题修复 & 功能扩展

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

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

modularavel/imgenerator

Composer 安装命令:

composer require modularavel/imgenerator

包简介

This is my package image

README 文档

README

Dynamically image resizes by url parameters... fast and easy to use and/or customize.

Server Requirements

This should go without saying really but TimThumb requires PHP and the GD image library. These are really really common so you shouldn’t have any problems. If you find yourself without these installed then ask your webhost and many will install the software for you – if they don’t do the installation it’s probably worth considering a new host.

File Permissions

Some web hosts won’t execute PHP code if it sits in directories that have permissions set to 777. So make sure that any directories ‘above’ the timthumb.php file are set to a normal level of permissions (644 is good).

Image Formats

Make sure that the images are one of .JPG, .JPEG, .GIF, or .PNG, or they won’t be resized!

Ensure if the cache/index.html empty file exists

To prevent the cache files from being browsable, an index.html file is created in the cache directory. This file should have it’s permissions set to 666

Installation

You can install the package via composer:

composer require modularavel/imgenerator

You can publish the config file with:

php artisan vendor:publish --tag="imgenerator-config"

This is the contents of the published config file:

return [
    'source' => [
        'filesystem' => env('MODULARAVEL_IMGENERATOR_SOURCE_FILESYSTEM', 'public'), // Options: "local", "public", "s3"
    ],
    'cache' => [
        'folder' => env('MODULARAVEL_IMGENERATOR_CACHE_FOLDER', '/cache'),
        'prefix' => env('MODULARAVEL_IMGENERATOR_CACHE_PREFIX', 'cache_'),
        'filesystem' => env('MODULARAVEL_IMGENERATOR_CACHE_FILESYSTEM', 'local'), // Options: "local", "public", "s3"
    ],
    'allow_external_sites' => env('MODULARAVEL_IMGENERATOR_ALLOW_EXTERNAL_SITES', true),
    'allow_all_external_sites' => env('MODULARAVEL_IMGENERATOR_ALLOW_ALL_EXTERNAL_SITES', true),
    'allowed_external_hosts' => env('MODULARAVEL_IMGENERATOR_ALLOWED_EXTERNAL_HOSTS', [
        'facebook.com',
        'img.youtube.com',
        'upload.wikimedia.org',
        'imgur.com',
        'amazonaws.com',
    ]),
];

Proportional Image Scaling

Usage is simple. The mysterious zc (Zoom & Crop) parameter comes into action, simply give it the value of 2 and it will apply the borders as required.

The 'zc' parameter = Zoom & Crop

  • The zc parameter was introduced to TimThumb about 3 months after it was first published. The reason for the inclusion is that the scaling in the original version was purely scaling, there was no cropping. This meant that images could end up severely distorted.

  • With the new cropping modes this thought has ended. I have added some new scaling modes, as described below.

    0 - Resize to Fit specified dimensions (no cropping);
    1 - Crop and resize to best fit the dimensions (default);
    2 - Resize proportionally to fit entire image into specified dimensions, and add borders if required;
    3 - Resize proportionally adjusting size of scaled image so there are no borders gaps.
    

Image Filters

When I talk about image filters, I mean the types of effects you can get in Photoshop or most other image editors. Things like altering brightness and contrast, and blur or emboss. All this functionality is included in TimThumb.

The functionality is actually the implementation of a single PHP function called imagefilter. For more details you can check out the imagefilter documentation on php.net.

  • Add parameter "f" to your query url: ...&f=" IMAGE_FILTERS "
    • Or ?f="IMAGE_FILTERS" (when f = first url parameter)

        f=1,10
      
    • It’s probably easier to understand if you see it in practice so now would be a good time to view the demo.

      • The image filters and arguments that you can use are:

              1 = Negate – Invert colours
              2 = Grayscale – turn the image into shades of grey
              3 = Brightness – Adjust brightness of image. Requires 1 argument to specify the amount of brightness to add. Values can be negative to make the image darker.
              4 = Contrast – Adjust contrast of image. Requires 1 argument to specify the amount of contrast to apply. Values greater than 0 will reduce the contrast and less than 0 will increase the contrast.
              5 = Colorize/ Tint – Apply a colour wash to the image. Requires the most parameters of all filters. The arguments are RGBA
              6 = Edge Detect – Detect the edges on an image
              7 = Emboss – Emboss the image (give it a kind of depth), can look nice when combined with the colorize filter above.
              8 = Gaussian Blur – blur the image, unfortunately you can’t specify the amount, but you can apply the same filter multiple times (as shown in the demos)
              9 = Selective Blur – a different type of blur. Not sure what the difference is, but this blur is less strong than the Gaussian blur.
              10 = Mean Removal – Uses mean removal to create a “sketchy” effect.
              11 = Smooth – Makes the image smoother.
        

      Multiple Filters at once

      • To make this super flexible I thought it would be good if I could chain the filters together to use multiple filters on a single image. To do this simply separate multiple filters using a pipe character and then pass the whole lot to TimThumb. For example the values below would apply a brightness of 10 to a grayscale image:

         f=2|1,10
        

        You can see some examples of multiple filters being used on the demo page.

      s – sharpen

      • One little extra I recently added is a sharpen filter. This is separate to the other filters above as it doesn’t use the imagefilter PHP command. All you have to do is add an s=1 value to the TimThumb query string.

        s=1
        

API Reference

Get all items

  GET /api/items
Parameter Type Description
api_key string Required. Your API key

Get item

  GET /api/items/${id}
Parameter Type Description
id string Required. Id of item to fetch

add(num1, num2)

Takes two numbers and returns their sum.

Usage

Add this to your .env file
# local | s3 | public
MODULARAVEL_IMGENERATOR_SOURCE_FILESYSTEM=s3
// Directly parameters
echo '<img src="/img?path=uploads/avatar.jpg&w=200&h=200&q=95&fs=s3" alt="My image" />';

// Or...
$image = route('modularavel::imgenerator', [
    // Image file path or image url
    "path" => storage()->drive(config('filesystem.default'))->url('uploads/avatar.jpg'),
    
    // Output image width
    "w" => 200,
    
    // Output image height
    "h" => 200,
    
    // Zoom crop control (numeric)
    "zc" => 1, // min: 0, max: 3
]);

echo '<img src="'.$image.'" alt="My image" />

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

modularavel/imgenerator 适用场景与选型建议

modularavel/imgenerator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「laravel」 「modularavel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 modularavel/imgenerator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 modularavel/imgenerator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-12