PHPackages                             imgix/imgix-php - 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. imgix/imgix-php

ActiveLibrary

imgix/imgix-php
===============

A PHP client library for generating URLs with imgix.

4.1.0(3y ago)1134.9M↓14.8%18[5 issues](https://github.com/imgix/imgix-php/issues)[3 PRs](https://github.com/imgix/imgix-php/pulls)20BSD-2-ClausePHPPHP ^8.0CI passing

Since Oct 2Pushed 1y ago13 watchersCompare

[ Source](https://github.com/imgix/imgix-php)[ Packagist](https://packagist.org/packages/imgix/imgix-php)[ RSS](/packages/imgix-imgix-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (23)Used By (20)

[![imgix logo](https://camo.githubusercontent.com/84c02063017a4b00f4563ccc538032c2cbf4f739a776127b6615173fb2f1c66c/68747470733a2f2f6173736574732e696d6769782e6e65742f73646b2d696d6769782d6c6f676f2e737667)](https://camo.githubusercontent.com/84c02063017a4b00f4563ccc538032c2cbf4f739a776127b6615173fb2f1c66c/68747470733a2f2f6173736574732e696d6769782e6e65742f73646b2d696d6769782d6c6f676f2e737667)

`imgix-php` is a client library for generating image URLs with [imgix](https://www.imgix.com/). It is tested under PHP versions `8.0`, `8.1` and `8.2`.

[![Version](https://camo.githubusercontent.com/b495d910390a02dded9f29f4c0097a41b251196034ca653eeb2a723bdbda4d10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d6769782f696d6769782d7068702e737667)](https://packagist.org/packages/imgix/imgix-php)[![Build Status](https://camo.githubusercontent.com/0609ba21ab4ac0e968333b92f7befe120f453d6ec5df16165c8553546c8780da/68747470733a2f2f636972636c6563692e636f6d2f67682f696d6769782f696d6769782d7068702e7376673f7374796c653d736869656c64)](https://circleci.com/gh/imgix/imgix-php)[![Downloads](https://camo.githubusercontent.com/b930d46532139616c650b7bcb19c9a38612dfddac1412a2eed1020179dad4016/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696d6769782f696d6769782d706870)](https://packagist.org/packages/imgix/imgix-php)[![License](https://camo.githubusercontent.com/6bb09b1a68818472a03c5bb112c106b476dc5cf6c38ea1f486e6ce5dc477bdfd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d6769782f696d6769782d706870)](https://github.com/imgix/imgix-php/blob/main/LICENSE)[![FOSSA Status](https://camo.githubusercontent.com/6921889fa4bf6d6981e8a90f639b6a52aefa9ba67e0614acee0de3843f6b6925/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246696d676978253246696d6769782d7068702e7376673f747970653d736869656c64)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php?ref=badge_shield)

---

- [Installation](#installation)
- [Usage](#usage)
- [Signed URLs](#signed-urls)
- [Srcset Generation](#srcset-generation)
    - [Fixed-Width Images](#fixed-width-images)
        - [Variable Quality](#variable-quality)
    - [Fluid-Width Images](#fluid-width-images)
        - [Custom Widths](#custom-widths)
        - [Width Ranges](#width-ranges)
        - [Width Tolerance](#width-tolerance)
- [The `ixlib` Parameter](#the-ixlib-parameter)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require imgix/imgix-php
```

Usage
-----

[](#usage)

To begin creating imgix URLs programmatically, add the php files to your project. The URL builder can be reused to create URLs for any images on the domains it is provided.

```
use Imgix\UrlBuilder;

$builder = new UrlBuilder("demos.imgix.net");
$params = array("w" => 100, "h" => 100);
echo $builder->createURL("bridge.png", $params);
// 'https://demos.imgix.net/bridge.png?h=100&w=100'
```

HTTPS support is available *by default*. However, if you need HTTP support, call `setUseHttps` on the builder:

```
use Imgix\UrlBuilder;

$builder = new UrlBuilder("demos.imgix.net");
$builder->setUseHttps(false);
$params = array("w" => 100, "h" => 100);
echo $builder->createURL("bridge.png", $params);
// 'http://demos.imgix.net/bridge.png?h=100&w=100'
```

Signed URLs
-----------

[](#signed-urls)

To produce a signed URL, you must enable secure URLs on your source and then provide your signature key to the URL builder.

```
use Imgix\UrlBuilder;

$builder = new UrlBuilder("demos.imgix.net");
$builder->setSignKey("test1234");
$params = array("w" => 100, "h" => 100);
echo $builder->createURL("bridge.png", $params);
// 'http://demos.imgix.net/bridge.png?h=100&w=100&s=bb8f3a2ab832e35997456823272103a4'
```

Srcset Generation
-----------------

[](#srcset-generation)

The imgix-php package allows for generation of custom srcset attributes, which can be invoked through the `createSrcSet` method. By default, the generated srcset will allow for responsive size switching by building a list of image-width mappings.

```
$builder = new UrlBuilder("demos.imgix.net", true, "my-key", false);
echo $builder->createSrcSet("image.png");
```

The above will produce the following srcset attribute value which can then be served to the client:

```
https://demos.imgix.net/image.png?w=100&s=e415797545a77a9d2842dedcfe539c9a 100w,
https://demos.imgix.net/image.png?w=116&s=b2da46f5c23ef13d5da30f0a4545f33f 116w,
https://demos.imgix.net/image.png?w=135&s=b61422dead929f893c04b8ff839bb088 135w,
                                        ...
https://demos.imgix.net/image.png?w=7401&s=ad671301ed4663c3ce6e84cb646acb96 7401w,
https://demos.imgix.net/image.png?w=8192&s=a0fed46e2bbcc70ded13dc629aee5398 8192w
```

### Fixed-Width Images

[](#fixed-width-images)

In cases where enough information is provided about an image's dimensions, `createSrcSet` will instead build a srcset that will allow for an image to be served at different resolutions. The parameters taken into consideration when determining if an image is fixed-width are `w` and `h`.

By invoking `createSrcSet` with either a width **or** height provided, a different srcset will be generated for a fixed-width image instead.

```
$builder = new UrlBuilder("demos.imgix.net", true, "my-key", false);
echo $builder->createSrcSet("image.png", array("h"=>800, "ar"=>"3:2", "fit"=>"crop"));
```

Will produce the following attribute value:

```
https://demos.imgix.net/image.png?ar=3%3A2&dpr=1&fit=crop&h=800&s=6cf5c443d1eb98bc3d96ea569fcef088 1x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=2&fit=crop&h=800&s=d60a61a5f34545922bd8dff4e53a0555 2x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=3&fit=crop&h=800&s=590f96aa426f8589eb7e449ebbeb66e7 3x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=4&fit=crop&h=800&s=c89c2fd3148957647e86cfc32ba20517 4x,
https://demos.imgix.net/image.png?ar=3%3A2&dpr=5&fit=crop&h=800&s=3d73af69d78d49eef0f81b4b5d718a2c 5x
```

For more information to better understand srcset, we highly recommend [Eric Portis' "Srcset and sizes" article](https://ericportis.com/posts/2014/srcset-sizes/) which goes into depth about the subject.

#### Variable Quality

[](#variable-quality)

This library will automatically append a variable `q` parameter mapped to each `dpr` parameter when generating a [fixed-width image](#fixed-width-images) srcset. This technique is commonly used to compensate for the increased file size of high-DPR images.

Since high-DPR images are displayed at a higher pixel density on devices, image quality can be lowered to reduce overall file size––without sacrificing perceived visual quality. For more information and examples of this technique in action, see [this blog post](https://blog.imgix.com/2016/03/30/dpr-quality).

This behavior will respect any overriding `q` value passed in as a parameter. Additionally, it can be disabled altogether by passing `$disableVariableQuality = true` to `createSrcSet()`'s `$options`.

This behavior specifically occurs when a [fixed-width image](#fixed-width-images) is rendered, for example:

```
// Note that `params=array("w" => 100)` allows `createSrcSet` to _infer_ the creation
// of a DPR based srcset attribute for fixed-width images.
$builder = new UrlBuilder("demos.imgix.net", true, "", false);
$params = array("w" => 100);
$srcset = $builder->createSrcSet($path="image.jpg", $params=$params);
```

The above will generate a srcset with the following `q` to `dpr` query `params`:

```
https://demos.imgix.net/image.jpg?dpr=1&q=75&w=100 1x,
https://demos.imgix.net/image.jpg?dpr=2&q=50&w=100 2x,
https://demos.imgix.net/image.jpg?dpr=3&q=35&w=100 3x,
https://demos.imgix.net/image.jpg?dpr=4&q=23&w=100 4x,
https://demos.imgix.net/image.jpg?dpr=5&q=20&w=100 5x'
```

### Fluid-Width Images

[](#fluid-width-images)

#### Custom Widths

[](#custom-widths)

In situations where specific widths are desired when generating `srcset` pairs, a user can specify them by passing an array of positive integers as `'widths'` within the `$options` array:

```
$builder = new UrlBuilder("demos.imgix.net", true, "", false);
$opts = array('widths' => array(144, 240, 320, 446, 640));
$srcset = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
```

```
https://demos.imgix.net/image.jpg?w=144 144w,
https://demos.imgix.net/image.jpg?w=240 240w,
https://demos.imgix.net/image.jpg?w=320 320w,
https://demos.imgix.net/image.jpg?w=446 446w,
https://demos.imgix.net/image.jpg?w=640 640w
```

**Note**: in situations where a `srcset` is being rendered as a [fixed-width](#fixed-width-images) srcset, any custom `widths` passed in will be ignored.

Additionally, if both `widths` and a width `tol`erance are passed to the `createSrcSet` method, the custom widths list will take precedence.

#### Width Ranges

[](#width-ranges)

In certain circumstances, you may want to limit the minimum or maximum value of the non-fixed `srcset` generated by the `createSrcSet` method. To do this, you can specify the widths at which a srcset should `start` and `stop`:

```
$builder = new UrlBuilder("demo.imgix.net", true, "", false);
$opts = array('start' => 500, 'stop' => 2000);
$srcset = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
```

Formatted version of the above srcset attribute:

```
https://demo.imgix.net/image.jpg?w=500 500w,
https://demo.imgix.net/image.jpg?w=580 580w,
https://demo.imgix.net/image.jpg?w=673 673w,
https://demo.imgix.net/image.jpg?w=780 780w,
https://demo.imgix.net/image.jpg?w=905 905w,
https://demo.imgix.net/image.jpg?w=1050 1050w,
https://demo.imgix.net/image.jpg?w=1218 1218w,
https://demo.imgix.net/image.jpg?w=1413 1413w,
https://demo.imgix.net/image.jpg?w=1639 1639w,
https://demo.imgix.net/image.jpg?w=1901 1901w,
https://demo.imgix.net/image.jpg?w=2000 2000w
```

#### Width Tolerance

[](#width-tolerance)

The `srcset` width `tol`erance dictates the maximum `tol`erated difference between an image's downloaded size and its rendered size.

For example, setting this value to `10` means that an image will not render more than 10% larger or smaller than its native size. In practice, the image URLs generated for a width-based srcset attribute will grow by twice this rate.

A lower tolerance means images will render closer to their native size (thereby increasing perceived image quality), but a large srcset list will be generated and consequently users may experience lower rates of cache-hit for pre-rendered images on your site.

By default, srcset width `tol`erance is set to 8 percent, which we consider to be the ideal rate for maximizing cache hits without sacrificing visual quality. Users can specify their own width tolerance by providing a positive scalar value as width `tol`erance:

```
$builder = new UrlBuilder("demo.imgix.net", true, "", false);
$opts = array('start' => 100, 'stop' => 384, 'tol' => 0.20);
$srcset = $builder->createSrcSet($path="image.jpg", $params=array(), $options=$opts);
```

In this case, the width `tol`erance is set to 20 percent, which will be reflected in the difference between subsequent widths in a srcset pair:

```
https://demo.imgix.net/image.jpg?w=100 100w,
https://demo.imgix.net/image.jpg?w=140 140w,
https://demo.imgix.net/image.jpg?w=196 196w,
https://demo.imgix.net/image.jpg?w=274 274w,
https://demo.imgix.net/image.jpg?w=384 384w
```

The `ixlib` Parameter
---------------------

[](#the-ixlib-parameter)

For security and diagnostic purposes, we sign all requests with the language and version of library used to generate the URL.

This can be disabled by setting `setIncludeLibraryParam` to `False` like so:

```
$builder = new UrlBuilder("demo.imgix.net", true, "", false);
// Or by calling `setIncludeLibraryParam`
$builder->setIncludeLibraryParam(false);
```

License
-------

[](#license)

[![FOSSA Status](https://camo.githubusercontent.com/a1d28d29f97c383cd054ab422a9ddb7723e5b2538abd921a90c339ceef6e9b93/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d253246696d676978253246696d6769782d7068702e7376673f747970653d6c61726765)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php?ref=badge_large)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity58

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~152 days

Recently: every ~258 days

Total

21

Last Release

1204d ago

Major Versions

1.2.1 → 2.0.02018-03-05

2.3.0 → 3.0.02019-06-11

3.3.1 → 4.0.02023-01-19

PHP version history (3 changes)1.0.1PHP &gt;=5.3

3.3.1PHP &gt;=7.3

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/296a86564d7ba93ce2429381567207122b6a02a283d400423ed8e6ec738ba068?d=identicon)[imgix](/maintainers/imgix)

---

Top Contributors

[![adevade](https://avatars.githubusercontent.com/u/1066486?v=4)](https://github.com/adevade "adevade (30 commits)")[![luqven](https://avatars.githubusercontent.com/u/16711614?v=4)](https://github.com/luqven "luqven (21 commits)")[![kellysutton](https://avatars.githubusercontent.com/u/47004?v=4)](https://github.com/kellysutton "kellysutton (14 commits)")[![ericdeansanchez](https://avatars.githubusercontent.com/u/22702087?v=4)](https://github.com/ericdeansanchez "ericdeansanchez (13 commits)")[![paulstraw](https://avatars.githubusercontent.com/u/117288?v=4)](https://github.com/paulstraw "paulstraw (11 commits)")[![jacktasia](https://avatars.githubusercontent.com/u/31308?v=4)](https://github.com/jacktasia "jacktasia (8 commits)")[![frederickfogerty](https://avatars.githubusercontent.com/u/615334?v=4)](https://github.com/frederickfogerty "frederickfogerty (8 commits)")[![shakaran](https://avatars.githubusercontent.com/u/14254?v=4)](https://github.com/shakaran "shakaran (5 commits)")[![hashknot](https://avatars.githubusercontent.com/u/1668396?v=4)](https://github.com/hashknot "hashknot (5 commits)")[![jayeb](https://avatars.githubusercontent.com/u/609840?v=4)](https://github.com/jayeb "jayeb (4 commits)")[![sherwinski](https://avatars.githubusercontent.com/u/15919091?v=4)](https://github.com/sherwinski "sherwinski (4 commits)")[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (1 commits)")[![seanislegend](https://avatars.githubusercontent.com/u/1477984?v=4)](https://github.com/seanislegend "seanislegend (1 commits)")[![snowtigersoft](https://avatars.githubusercontent.com/u/3327253?v=4)](https://github.com/snowtigersoft "snowtigersoft (1 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![davidrapson](https://avatars.githubusercontent.com/u/123386?v=4)](https://github.com/davidrapson "davidrapson (1 commits)")[![bjora857](https://avatars.githubusercontent.com/u/237053?v=4)](https://github.com/bjora857 "bjora857 (1 commits)")

---

Tags

hacktoberfestimagesimgixphpsigning-imgix-urlssrcsrcseturl-builderimgix

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/imgix-imgix-php/health.svg)

```
[![Health](https://phpackages.com/badges/imgix-imgix-php/health.svg)](https://phpackages.com/packages/imgix-imgix-php)
```

###  Alternatives

[nystudio107/craft-imageoptimize

Automatically create &amp; optimize responsive image transforms, using either native Craft transforms or a service like imgix, with zero template changes.

232337.2k16](/packages/nystudio107-craft-imageoptimize)[ilab/ilab-media-tools

Tools for cropping, uploading to S3, serving through Imgix

119102.7k1](/packages/ilab-ilab-media-tools)[imgix-wordpress/images-via-imgix

imgix WordPress plugin

555.6k](/packages/imgix-wordpress-images-via-imgix)[nasyrov/laravel-imgix

Laravel package for generating URLs with Imgix.

1447.5k2](/packages/nasyrov-laravel-imgix)[superbig/craft3-imgix

Use Imgix with Craft

1226.9k](/packages/superbig-craft3-imgix)[otisz/laravel-imgix

1419.4k](/packages/otisz-laravel-imgix)

PHPackages © 2026

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