PHPackages                             aneeskhan47/php-cloudflare-image-resizing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. aneeskhan47/php-cloudflare-image-resizing

ActiveLibrary[Image &amp; Media](/categories/media)

aneeskhan47/php-cloudflare-image-resizing
=========================================

A PHP package to generate Cloudflare Image Resizing/Optimization URLs

v1.2.0(1mo ago)20975↓25%MITPHPPHP ^8.2.0CI passing

Since Aug 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/aneeskhan47/php-cloudflare-image-resizing)[ Packagist](https://packagist.org/packages/aneeskhan47/php-cloudflare-image-resizing)[ Fund](https://www.paypal.com/paypalme/aneeskhan47)[ RSS](/packages/aneeskhan47-php-cloudflare-image-resizing/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (10)Versions (6)Used By (0)

 [![PHP Cloudflare Image](https://raw.githubusercontent.com/aneeskhan47/php-cloudflare-image-resizing/main/art/banner.png)](https://raw.githubusercontent.com/aneeskhan47/php-cloudflare-image-resizing/main/art/banner.png)

 [![GitHub Workflow Status (master)](https://github.com/aneeskhan47/php-cloudflare-image-resizing/actions/workflows/tests.yml/badge.svg)](https://github.com/aneeskhan47/php-cloudflare-image-resizing/actions) [![Total Downloads](https://camo.githubusercontent.com/b6f58a6cd2bd378a531b85d6283b454b3232a207ee1c44fde796a2849231cb6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6565736b68616e34372f7068702d636c6f7564666c6172652d696d6167652d726573697a696e67)](https://packagist.org/packages/aneeskhan47/php-cloudflare-image-resizing) [![Latest Version](https://camo.githubusercontent.com/141fde5f2f199b4dea8b690a67b96a11d2eb9b2ffb3c94e88b316846a369f85e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e6565736b68616e34372f7068702d636c6f7564666c6172652d696d6167652d726573697a696e67)](https://packagist.org/packages/aneeskhan47/php-cloudflare-image-resizing) [![License](https://camo.githubusercontent.com/f2a1ab52c9bd9f07ce9668de09e9b9860621c19f3b903c85668f48425b994bd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e6565736b68616e34372f7068702d636c6f7564666c6172652d696d6167652d726573697a696e67)](https://packagist.org/packages/aneeskhan47/php-cloudflare-image-resizing)

---

A PHP package to generate Cloudflare Image Resizing/Optimization URLs. based on [Cloudflare Image Optimization](https://developers.cloudflare.com/images/optimization/features/).

### ⚡️ Installation

[](#️-installation)

> **Requires [PHP 8.2+](https://php.net/releases/)**

```
composer require aneeskhan47/php-cloudflare-image-resizing
```

---

### ❓ How it works

[](#-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](https://developers.cloudflare.com/images/optimization/features/).

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

---

### 🚀 Usage

[](#-usage)

#### Generating a URL without any transformations

[](#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

[](#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

[](#available-transformations)

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

### 🧪 Testing

[](#-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

[](#-changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

---

### 🤝 Contributing

[](#-contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

---

### 🔒 Security

[](#-security)

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

---

### 🙌 Credits

[](#-credits)

- [Anees Khan](https://github.com/aneeskhan47)
- [All Contributors](../../contributors)

---

### 📜 License

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

### 🔧 Skeleton PHP Boilerplate

[](#-skeleton-php-boilerplate)

This package was generated using the [Skeleton PHP](https://github.com/nunomaduro/skeleton-php) by **[Nuno Maduro](https://twitter.com/enunomaduro)**.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance92

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~255 days

Total

5

Last Release

39d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a90a10890bedc5d9ef6888329f3ce4de29869567404ad4f32cd58491525720b9?d=identicon)[aneeskhan47](/maintainers/aneeskhan47)

---

Top Contributors

[![aneeskhan47](https://avatars.githubusercontent.com/u/30714223?v=4)](https://github.com/aneeskhan47 "aneeskhan47 (20 commits)")

---

Tags

cloudfarecloudflare-imagecloudflare-image-optimizationcloudflare-image-resizingcloudflare-imagesimage-optimizationimage-resizeimage-resizingphpurlphpimageoptimizationcloudflarecdnresizing

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aneeskhan47-php-cloudflare-image-resizing/health.svg)

```
[![Health](https://phpackages.com/badges/aneeskhan47-php-cloudflare-image-resizing/health.svg)](https://phpackages.com/packages/aneeskhan47-php-cloudflare-image-resizing)
```

###  Alternatives

[ps/image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

9151.7M25](/packages/ps-image-optimizer)[ambroisemaupate/intervention-request

A customizable Intervention Image wrapper to use image simple re-sampling features over urls and a configurable cache.

4344.0k2](/packages/ambroisemaupate-intervention-request)[toinekamps/responsive-pics

Responsive Pics is a Wordpress tool for resizing images on the fly.

832.4k](/packages/toinekamps-responsive-pics)[gtuk/image-optimizer

PHP image optimizer for png, jpeg and gif files. It uses mozjpeg, pngquant and gifsicle for the optimization process

161.6k](/packages/gtuk-image-optimizer)[lciolecki/php-image-optimizer

PHP image file optimizer (uses https://github.com/bensquire/php-image-optim)

347.4k](/packages/lciolecki-php-image-optimizer)[somehow-digital/typo3-media-processing

Media Processing

121.3k](/packages/somehow-digital-typo3-media-processing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
