{"id":18708637,"url":"https://github.com/imgix/imgix-php","last_synced_at":"2025-05-15T12:05:04.495Z","repository":{"id":20879150,"uuid":"24166335","full_name":"imgix/imgix-php","owner":"imgix","description":"A PHP client library for generating URLs with imgix","archived":false,"fork":false,"pushed_at":"2024-12-14T12:16:30.000Z","size":175,"stargazers_count":112,"open_issues_count":8,"forks_count":19,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-14T22:18:16.700Z","etag":null,"topics":["hacktoberfest","images","imgix","php","signing-imgix-urls","src","srcset","url-builder"],"latest_commit_sha":null,"homepage":"https://www.imgix.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imgix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-17T23:38:25.000Z","updated_at":"2025-01-09T13:15:30.000Z","dependencies_parsed_at":"2025-01-04T03:03:34.561Z","dependency_job_id":"084a5371-08ce-42a3-8bc8-0a5a78383ceb","html_url":"https://github.com/imgix/imgix-php","commit_stats":{"total_commits":159,"total_committers":22,"mean_commits":"7.2272727272727275","dds":0.8113207547169812,"last_synced_commit":"b42231e6e249e57592c474b08f79fe67d34615d8"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imgix%2Fimgix-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imgix%2Fimgix-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imgix%2Fimgix-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imgix%2Fimgix-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imgix","download_url":"https://codeload.github.com/imgix/imgix-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","images","imgix","php","signing-imgix-urls","src","srcset","url-builder"],"created_at":"2024-11-07T12:24:22.317Z","updated_at":"2025-05-15T12:04:59.469Z","avatar_url":"https://github.com/imgix.png","language":"PHP","readme":"\u003c!-- ix-docs-ignore --\u003e\n![imgix logo](https://assets.imgix.net/sdk-imgix-logo.svg)\n\n`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`.\n\n[![Version](https://img.shields.io/packagist/v/imgix/imgix-php.svg)](https://packagist.org/packages/imgix/imgix-php)\n[![Build Status](https://circleci.com/gh/imgix/imgix-php.svg?style=shield)](https://circleci.com/gh/imgix/imgix-php)\n[![Downloads](https://img.shields.io/packagist/dt/imgix/imgix-php)](https://packagist.org/packages/imgix/imgix-php)\n[![License](https://img.shields.io/github/license/imgix/imgix-php)](https://github.com/imgix/imgix-php/blob/main/LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php?ref=badge_shield)\n\n---\n\u003c!-- /ix-docs-ignore --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Signed URLs](#signed-urls)\n- [Srcset Generation](#srcset-generation)\n    * [Fixed-Width Images](#fixed-width-images)\n        + [Variable Quality](#variable-quality)\n    * [Fluid-Width Images](#fluid-width-images)\n        + [Custom Widths](#custom-widths)\n        + [Width Ranges](#width-ranges)\n        + [Width Tolerance](#width-tolerance)\n- [The `ixlib` Parameter](#the-ixlib-parameter)\n- [License](#license)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require imgix/imgix-php\n```\n\n## Usage\n\nTo begin creating imgix URLs programmatically, add the php files to your project. The URL builder can be reused to create URLs for any\nimages on the domains it is provided.\n\n```php\nuse Imgix\\UrlBuilder;\n\n$builder = new UrlBuilder(\"demos.imgix.net\");\n$params = array(\"w\" =\u003e 100, \"h\" =\u003e 100);\necho $builder-\u003ecreateURL(\"bridge.png\", $params);\n// 'https://demos.imgix.net/bridge.png?h=100\u0026w=100'\n```\n\nHTTPS support is available _by default_. However, if you need HTTP support, call `setUseHttps` on the builder:\n\n```php\nuse Imgix\\UrlBuilder;\n\n$builder = new UrlBuilder(\"demos.imgix.net\");\n$builder-\u003esetUseHttps(false);\n$params = array(\"w\" =\u003e 100, \"h\" =\u003e 100);\necho $builder-\u003ecreateURL(\"bridge.png\", $params);\n// 'http://demos.imgix.net/bridge.png?h=100\u0026w=100'\n```\n\n## Signed URLs\n\nTo produce a signed URL, you must enable secure URLs on your source and then\nprovide your signature key to the URL builder.\n\n```php\nuse Imgix\\UrlBuilder;\n\n$builder = new UrlBuilder(\"demos.imgix.net\");\n$builder-\u003esetSignKey(\"test1234\");\n$params = array(\"w\" =\u003e 100, \"h\" =\u003e 100);\necho $builder-\u003ecreateURL(\"bridge.png\", $params);\n// 'http://demos.imgix.net/bridge.png?h=100\u0026w=100\u0026s=bb8f3a2ab832e35997456823272103a4'\n```\n\n## Srcset Generation\n\nThe 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.\n\n```php\n$builder = new UrlBuilder(\"demos.imgix.net\", true, \"my-key\", false);\necho $builder-\u003ecreateSrcSet(\"image.png\");\n```\n\nThe above will produce the following srcset attribute value which can then be served to the client:\n\n``` html\nhttps://demos.imgix.net/image.png?w=100\u0026s=e415797545a77a9d2842dedcfe539c9a 100w,\nhttps://demos.imgix.net/image.png?w=116\u0026s=b2da46f5c23ef13d5da30f0a4545f33f 116w,\nhttps://demos.imgix.net/image.png?w=135\u0026s=b61422dead929f893c04b8ff839bb088 135w,\n                                        ...\nhttps://demos.imgix.net/image.png?w=7401\u0026s=ad671301ed4663c3ce6e84cb646acb96 7401w,\nhttps://demos.imgix.net/image.png?w=8192\u0026s=a0fed46e2bbcc70ded13dc629aee5398 8192w\n```\n\n### Fixed-Width Images\n\nIn 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`.\n\nBy invoking `createSrcSet` with either a width **or** height provided, a different srcset will be generated for a fixed-width image instead.\n\n```php\n$builder = new UrlBuilder(\"demos.imgix.net\", true, \"my-key\", false);\necho $builder-\u003ecreateSrcSet(\"image.png\", array(\"h\"=\u003e800, \"ar\"=\u003e\"3:2\", \"fit\"=\u003e\"crop\"));\n```\n\nWill produce the following attribute value:\n\n``` html\nhttps://demos.imgix.net/image.png?ar=3%3A2\u0026dpr=1\u0026fit=crop\u0026h=800\u0026s=6cf5c443d1eb98bc3d96ea569fcef088 1x,\nhttps://demos.imgix.net/image.png?ar=3%3A2\u0026dpr=2\u0026fit=crop\u0026h=800\u0026s=d60a61a5f34545922bd8dff4e53a0555 2x,\nhttps://demos.imgix.net/image.png?ar=3%3A2\u0026dpr=3\u0026fit=crop\u0026h=800\u0026s=590f96aa426f8589eb7e449ebbeb66e7 3x,\nhttps://demos.imgix.net/image.png?ar=3%3A2\u0026dpr=4\u0026fit=crop\u0026h=800\u0026s=c89c2fd3148957647e86cfc32ba20517 4x,\nhttps://demos.imgix.net/image.png?ar=3%3A2\u0026dpr=5\u0026fit=crop\u0026h=800\u0026s=3d73af69d78d49eef0f81b4b5d718a2c 5x\n```\n\nFor more information to better understand srcset, we highly recommend\n[Eric Portis' \"Srcset and sizes\" article](https://ericportis.com/posts/2014/srcset-sizes/) which goes into depth about the subject.\n\n#### Variable Quality\n\nThis 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.\n\nSince 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).\n\nThis 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`.\n\nThis behavior specifically occurs when a [fixed-width image](#fixed-width-images) is rendered, for example:\n\n```php\n// Note that `params=array(\"w\" =\u003e 100)` allows `createSrcSet` to _infer_ the creation\n// of a DPR based srcset attribute for fixed-width images.\n$builder = new UrlBuilder(\"demos.imgix.net\", true, \"\", false);\n$params = array(\"w\" =\u003e 100);\n$srcset = $builder-\u003ecreateSrcSet($path=\"image.jpg\", $params=$params);\n```\n\nThe above will generate a srcset with the following `q` to `dpr` query `params`:\n\n```html\nhttps://demos.imgix.net/image.jpg?dpr=1\u0026q=75\u0026w=100 1x,\nhttps://demos.imgix.net/image.jpg?dpr=2\u0026q=50\u0026w=100 2x,\nhttps://demos.imgix.net/image.jpg?dpr=3\u0026q=35\u0026w=100 3x,\nhttps://demos.imgix.net/image.jpg?dpr=4\u0026q=23\u0026w=100 4x,\nhttps://demos.imgix.net/image.jpg?dpr=5\u0026q=20\u0026w=100 5x'\n```\n\n### Fluid-Width Images\n\n#### Custom Widths\n\nIn 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:\n\n``` php\n$builder = new UrlBuilder(\"demos.imgix.net\", true, \"\", false);\n$opts = array('widths' =\u003e array(144, 240, 320, 446, 640));\n$srcset = $builder-\u003ecreateSrcSet($path=\"image.jpg\", $params=array(), $options=$opts);\n```\n\n```html\nhttps://demos.imgix.net/image.jpg?w=144 144w,\nhttps://demos.imgix.net/image.jpg?w=240 240w,\nhttps://demos.imgix.net/image.jpg?w=320 320w,\nhttps://demos.imgix.net/image.jpg?w=446 446w,\nhttps://demos.imgix.net/image.jpg?w=640 640w\n```\n\n**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.\n\nAdditionally, if both `widths` and a width `tol`erance are passed to the `createSrcSet` method, the custom widths list will take precedence.\n\n#### Width Ranges\n\nIn 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`:\n\n```php\n$builder = new UrlBuilder(\"demo.imgix.net\", true, \"\", false);\n$opts = array('start' =\u003e 500, 'stop' =\u003e 2000);\n$srcset = $builder-\u003ecreateSrcSet($path=\"image.jpg\", $params=array(), $options=$opts);\n```\n\nFormatted version of the above srcset attribute:\n\n``` html\nhttps://demo.imgix.net/image.jpg?w=500 500w,\nhttps://demo.imgix.net/image.jpg?w=580 580w,\nhttps://demo.imgix.net/image.jpg?w=673 673w,\nhttps://demo.imgix.net/image.jpg?w=780 780w,\nhttps://demo.imgix.net/image.jpg?w=905 905w,\nhttps://demo.imgix.net/image.jpg?w=1050 1050w,\nhttps://demo.imgix.net/image.jpg?w=1218 1218w,\nhttps://demo.imgix.net/image.jpg?w=1413 1413w,\nhttps://demo.imgix.net/image.jpg?w=1639 1639w,\nhttps://demo.imgix.net/image.jpg?w=1901 1901w,\nhttps://demo.imgix.net/image.jpg?w=2000 2000w\n```\n\n#### Width Tolerance\n\nThe `srcset` width `tol`erance dictates the maximum `tol`erated difference between an image's downloaded size and its rendered size.\n\nFor 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.\n\nA 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.\n\nBy 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:\n\n```php\n$builder = new UrlBuilder(\"demo.imgix.net\", true, \"\", false);\n$opts = array('start' =\u003e 100, 'stop' =\u003e 384, 'tol' =\u003e 0.20);\n$srcset = $builder-\u003ecreateSrcSet($path=\"image.jpg\", $params=array(), $options=$opts);\n```\n\nIn 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:\n\n```html\nhttps://demo.imgix.net/image.jpg?w=100 100w,\nhttps://demo.imgix.net/image.jpg?w=140 140w,\nhttps://demo.imgix.net/image.jpg?w=196 196w,\nhttps://demo.imgix.net/image.jpg?w=274 274w,\nhttps://demo.imgix.net/image.jpg?w=384 384w\n```\n\n## The `ixlib` Parameter\n\nFor security and diagnostic purposes, we sign all requests with the language and version of library used to generate the URL.\n\nThis can be disabled by setting `setIncludeLibraryParam` to `False` like so:\n\n``` php\n$builder = new UrlBuilder(\"demo.imgix.net\", true, \"\", false);\n// Or by calling `setIncludeLibraryParam`\n$builder-\u003esetIncludeLibraryParam(false);\n```\n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-php?ref=badge_large)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimgix%2Fimgix-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimgix%2Fimgix-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimgix%2Fimgix-php/lists"}