定制 aneeskhan47/php-cloudflare-image-resizing 二次开发

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

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

aneeskhan47/php-cloudflare-image-resizing

Composer 安装命令:

composer require aneeskhan47/php-cloudflare-image-resizing

包简介

A PHP package to generate Cloudflare Image Resizing/Optimization URLs

README 文档

README

PHP Cloudflare Image

GitHub Workflow Status (master) Total Downloads Latest Version License

A PHP package to generate Cloudflare Image Resizing/Optimization URLs. based on Cloudflare Image Optimization.

⚡️ Installation

Requires PHP 8.2+

composer require aneeskhan47/php-cloudflare-image-resizing

❓ How it works

Cloudflare Image Resizing/Optimization is a feature that allows you to resize, crop, and convert images by simply changing the URL of the image. This is done by adding a set of image transformation parameters to the URL of the image, which Cloudflare will then use to generate a new image on the fly.

So just by adding /cdn-cgi/image/ to the beginning of the URL, you can utilize Cloudflare's image resizing feature.

You can convert and resize images by requesting them via a specially-formatted URL. This way you do not need to write any code, only change HTML markup of your website to use the new URLs.

For more information, please see the Cloudflare Image Optimization documentation.

This package provides a fluent API to generate Cloudflare Image Resizing/Optimization URLs.

🚀 Usage

Generating a URL without any transformations

use AneesKhan47\CloudflareImageResizing\CFImageResizing;

$url = 'https://example.com/uploads/2023/image.jpg';

$image = CFImageResizing::make($url)->build();

// output: 
// https://example.com/cdn-cgi/image/format=auto/uploads/2023/image.jpg

// note: format=auto is added by default to the URL as it is required 
// by Cloudflare to have atleast one transformation applied.

Generating a URL with transformations

use AneesKhan47\CloudflareImageResizing\CFImageResizing;

$url = 'https://example.com/uploads/2023/image.jpg';

$image = CFImageResizing::make($url)
                        ->width(300)
                        ->height(300)
                        ->webp()
                        ->quality(80)
                        ->build();

// output: 
// https://example.com/cdn-cgi/image/width=300,height=300,format=webp,quality=80/uploads/2023/image.jpg

Available transformations

Transformation Description Cloudflare Docs
anim(bool) Whether to animate the image Docs
background(string) Background color in CSS format (hex, rgb, rgba, hsl, hsla) Docs
blur(int) Blur radius between 1 (slight blur) and 250 (maximum) Docs
brightness(string) Value of 1.0 equals no change, 0.5 equals half brightness, 2.0 equals twice as bright Docs
compression(string) Compression value (e.g. fast) Docs
contrast(float) Value of 1.0 equals no change, 0.5 equals low contrast, 2.0 equals high contrast Docs
dpr(int) Device pixel ratio multiplier for width/height Docs
fit(string) Fit mode (scale-down, contain, cover, crop, pad, squeeze) Docs
flip(string) Flip horizontally (h), vertically (v), or both (hv) Docs
format(string) Output format (auto, avif, webp, jpeg, baseline-jpeg, json) Docs
avif() Set the format to avif. Alias for format('avif'). Docs
webp() Set the format to webp. Alias for format('webp'). Docs
jpeg() Set the format to jpeg. Alias for format('jpeg'). Docs
baselineJpeg() Set the format to baseline-jpeg. Alias for format('baseline-jpeg'). Docs
json() Set the format to json. Alias for format('json'). Docs
gamma(float) Value of 1.0 equals no change, 0.5 darkens, 2.0 lightens Docs
gravity(string) Cropping gravity (auto, face, left, right, top, bottom, or XxY coordinates) Docs
height(int) Height in pixels Docs
metadata(string) Metadata preservation mode (keep, copyright, none) Docs
onerror(string) Error handling mode (redirect) Docs
quality(int|string) Quality 1-100 or perceptual (high, medium-high, medium-low, low) Docs
rotate(int) Rotation degrees (90, 180, or 270) Docs
saturation(float) Value of 1.0 equals no change, 0.5 equals half saturation, 2.0 equals twice as saturated Docs
segment(string) Background removal (foreground) Docs
segmentForeground() Alias for segment('foreground') Docs
sharpen(float) Sharpening strength between 0 (none) and 10 (maximum) Docs
slowConnectionQuality(int|string) Override quality on slow connections Docs
trim(string) Trim value (border, top;right;bottom;left, etc.) Docs
trimBorder() Trim sides based on border color Docs
trimBorderColor(string) Border color to trim when using trim=border Docs
trimBorderTolerance(int) Color match tolerance (0-255) when using trim=border Docs
trimBorderKeep(int) Pixels of border to leave when using trim=border Docs
width(int|string) Width in pixels, or auto for responsive width Docs
zoom(float) Face crop zoom (0.0-1.0) when using gravity=face Docs

🧪 Testing

🧹 Keep a modern codebase with Pint:

composer lint

✅ Run refactors using Rector

composer refacto

⚗️ Run static analysis using PHPStan:

composer test:types

✅ Run unit tests using PEST

composer test:unit

🚀 Run the entire test suite:

composer test

📝 Changelog

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

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security-related issues, please email kingkhan2388@gmail.com instead of using the issue tracker.

🙌 Credits

📜 License

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

🔧 Skeleton PHP Boilerplate

This package was generated using the Skeleton PHP by Nuno Maduro.

aneeskhan47/php-cloudflare-image-resizing 适用场景与选型建议

aneeskhan47/php-cloudflare-image-resizing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 946 次下载、GitHub Stars 达 20, 最近一次更新时间为 2023 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 aneeskhan47/php-cloudflare-image-resizing 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 20
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-07