imgix 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aacdd5bdf7d625eec3ee921e77ae5abc4ce477d3acb3fe157cd8dfbba17c290b
4
+ data.tar.gz: fe73df2f92e6fdbba85ea88bf5354e0a3ae312f2d5d7807cf2d1e7d2085571d5
5
+ SHA512:
6
+ metadata.gz: c61d6b8c35bc9ad6133eb72829be8afccb9aec4822775a2df0649b5c2536ba97a8b28884cc2559d3764b9cd66dd1dcd38dca8356be43f66dd8a3157e0c66db49
7
+ data.tar.gz: f08aab23f7211ee429f017a9ac38f9bcf6c67fd2290814b1c7503f02d3e29a6265b7f171afbe23ccd09be37fd2083104d35ea8de59c17eaf1bc764ab24468db9
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Describe the bug**
13
+ A clear and concise description of what the bug is.
14
+
15
+ **To Reproduce**
16
+ Steps to reproduce the behavior:
17
+
18
+ **Expected behavior**
19
+ A clear and concise description of what you expected to happen.
20
+
21
+ **Screenshots**
22
+ If applicable, add screenshots to help explain your problem.
23
+
24
+ **Information:**
25
+ - imgix-rb version: [e.g. 2.0.0]
26
+
27
+ **Additional context**
28
+ Add any other context about the problem here.
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Before you submit:**
13
+
14
+ - [ ] Please search through the [existing issues](https://github.com/imgix/imgix-rb/issues?utf8=%E2%9C%93&q=is%3Aissue) to see if your feature has already been discussed.
15
+ - [ ] Please take a moment to find out whether your idea fits with the scope and aims of this project.
16
+
17
+ **Is your feature request related to a problem? Please describe.**
18
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
19
+
20
+ **Describe the solution you'd like**
21
+ A clear and concise description of what you want to happen.
22
+
23
+ **Describe alternatives you've considered**
24
+ A clear and concise description of any alternative solutions or features you've considered.
25
+
26
+ **Additional context**
27
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Question
3
+ about: Ask a question about the project
4
+ title: ''
5
+ labels: ''
6
+ assignees:
7
+
8
+ ---
9
+
10
+ Please provide the following information and someone from @imgix/imgix-sdk-team will respond to your issue shortly.
11
+
12
+ **Before you submit:**
13
+
14
+ - [ ] Please search through the [existing issues]([existing issues](https://github.com/imgix/imgix-rb/issues?utf8=%E2%9C%93&q=is%3Aissue)) to see if your question has already been discussed.
15
+
16
+ **Question**
17
+ A clear and concise description of your question.
@@ -0,0 +1,73 @@
1
+ <!--
2
+ Hello, and thanks for contributing to imgix-rb! 🎉🙌
3
+ Please take a second to fill out PRs with the following template!
4
+ -->
5
+
6
+ # Description
7
+
8
+ <!-- What is accomplished by this PR? If there is something potentially controversial in your PR, please take a moment to tell us about your choices. -->
9
+
10
+ <!--
11
+ Please use the checklist that is most closely related to your PR, and delete the other checklists. -->
12
+
13
+ ## Checklist: Fixing typos/Doc change
14
+
15
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
16
+
17
+ ## Checklist: Bug Fix
18
+
19
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
20
+ - [ ] All existing unit tests are still passing (if applicable)
21
+ - [ ] Add new passing unit tests to cover the code introduced by your PR
22
+ - [ ] Update the readme
23
+ - [ ] Update or add any necessary API documentation
24
+ - [ ] Add some [steps](#steps-to-test) so we can test your bug fix
25
+
26
+ ## Checklist: New Feature
27
+
28
+ - [ ] Each commit follows the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) format: e.g. `chore(readme): fixed typo`. See the end of this file for more information.
29
+ - [ ] Any breaking changes are specified on the commit on which they are introduced with `BREAKING CHANGE` in the body of the commit.
30
+ - [ ] If this is a big feature with breaking changes, consider [opening an issue][issues] to discuss first. This is completely up to you, but please keep in mind that your PR might not be accepted.
31
+ - [ ] Run unit tests to ensure all existing tests are still passing
32
+ - [ ] Add new passing unit tests to cover the code introduced by your PR
33
+ - [ ] Update the readme
34
+ - [ ] Add some [steps](#steps-to-test) so we can test your cool new feature!
35
+
36
+ ## Steps to Test
37
+
38
+ <!-- Delete this selction if you are just submitting a doc change/small fix -->
39
+
40
+ <!-- A code example or a set of steps is preferred -->
41
+
42
+ Related issue: [e.g. #42]
43
+
44
+ Code:
45
+
46
+ ```rb
47
+ // A standalone Ruby example of what the PR solves
48
+ ```
49
+
50
+ <!-- A link to a codepen/codesandbox is also an option. -->
51
+
52
+ <!--
53
+
54
+ ## Conventional Commit Spec
55
+
56
+ PR titles should be in the format `<type>(<scope>): <description>`. For example: `chore(readme): fix typo`
57
+
58
+ `type` can be any of the follow:
59
+ - `feat`: a feature, or breaking change
60
+ - `fix`: a bug-fix
61
+ - `test`: Adding missing tests or correcting existing tests
62
+ - `docs`: documentation only changes (readme, changelog, contributing guide)
63
+ - `refactor`: a code change that neither fixes a bug nor adds a feature
64
+ - `chore`: reoccurring tasks for project maintainability (example scopes: release, deps)
65
+ - `config`: changes to tooling configurations used in the project
66
+ - `build`: changes that affect the build system or external dependencies (example scopes: npm, bundler, gradle)
67
+ - `ci`: changes to CI configuration files and scripts (example scopes: travis)
68
+ - `perf`: a code change that improves performance
69
+ - `style`: changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
70
+
71
+ `scope` is optional, and can be anything.
72
+ `description` should be a short description of the change, written in the imperative-mood.
73
+ -->
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-version
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,21 @@
1
+ dist: trusty
2
+ language: ruby
3
+ bundler_args: --without development
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.2.4
7
+ - 2.1.8
8
+ - jruby-9.2.11.0
9
+
10
+ jobs:
11
+ # Use `fast_finish`, don't wait for any allowed failures.
12
+ fast_finish: true
13
+
14
+ include:
15
+ - name: Rubinius
16
+ rvm: rbx-3.107
17
+ dist: trusty
18
+
19
+ allow_failures:
20
+ - name: Rubinius
21
+
@@ -0,0 +1,84 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [3.3.0](https://github.com/imgix/imgix-rb/compare/3.2.1...3.3.0) - July 21, 2020
7
+
8
+ * fix: warn prefix-with-args is deprecated ([#78](https://github.com/imgix/imgix-rb/pull/78))
9
+ * fix: warn host has been deprecated in favor of domain ([#76](https://github.com/imgix/imgix-rb/pull/76))
10
+ * fix: deprecate ALIASES and corresponding define_method(s) ([#75](https://github.com/imgix/imgix-rb/pull/75))
11
+ * fix: deprecate ParamHelpers.rect ([#74](https://github.com/imgix/imgix-rb/pull/74))
12
+ * fix: allow rbx-3.107 to fail (travis-config) ([#70](https://github.com/imgix/imgix-rb/pull/70))
13
+ * fix: remove ensure even requirement ([#69](https://github.com/imgix/imgix-rb/pull/69))
14
+
15
+ ## [3.2.1](https://github.com/imgix/imgix-rb/compare/3.2.0...3.2.1) - November 15, 2019
16
+
17
+ * fix: duplicate entries when using `min_width` or `max_width` ([#59](https://github.com/imgix/imgix-rb/pull/59))
18
+
19
+ ## [3.2.0](https://github.com/imgix/imgix-rb/compare/3.1.1...3.2.0) - November 15, 2019
20
+
21
+ * feat: append variable qualities to dpr srcsets ([#58](https://github.com/imgix/imgix-rb/pull/58))
22
+ * refactor: pass srcset modifiers through the `options` parameter ([#57](https://github.com/imgix/imgix-rb/pull/57))
23
+ * feat: support defining a min and max width range ([#56](https://github.com/imgix/imgix-rb/pull/56))
24
+ * feat: add ability to pass in custom widths ([#55](https://github.com/imgix/imgix-rb/pull/55))
25
+ * feat: add ability to configure the srcset width tolerance ([#54](https://github.com/imgix/imgix-rb/pull/54))
26
+ * style: drop redundant explicit return statements ([#52](https://github.com/imgix/imgix-rb/pull/52))
27
+
28
+ ## [3.1.1](https://github.com/imgix/imgix-rb/compare/3.1.0...3.1.1) - July 28, 2019
29
+
30
+ * fix: include dpr parameter when generating a DPR srcset ([#48](https://github.com/imgix/imgix-rb/pull/48))
31
+ * ci(travis): change build dist to trusty and remove bundler script ([#49](https://github.com/imgix/imgix-rb/pull/49))
32
+
33
+ ## [3.1.0](https://github.com/imgix/imgix-rb/compare/3.0.0...3.1.0) - July 28, 2019
34
+
35
+ * feat: add srcset generation ([#47](https://github.com/imgix/imgix-rb/pull/47))
36
+
37
+ ## [3.0.0](https://github.com/imgix/imgix-rb/compare/2.1.0...3.0.0) - June 7, 2019
38
+
39
+ * fix: remove deprecated domain sharding functionality ([#46](https://github.com/imgix/imgix-rb/pull/46))
40
+
41
+ ## [2.1.0](https://github.com/imgix/imgix-rb/compare/2.0.0...2.1.0) - May 7, 2019
42
+
43
+ * Deprecate domain sharding ([#43](https://github.com/imgix/imgix-rb/pull/43)) ([#45](https://github.com/imgix/imgix-rb/pull/45))
44
+
45
+ ## [2.0.0] - February 25, 2019
46
+
47
+ * Add domain validation during Client initialization [#42](https://github.com/imgix/imgix-rb/pull/42)
48
+ * Expand Travis CI config to include bundler v2.x [#41](https://github.com/imgix/imgix-rb/pull/41)
49
+
50
+ ## [1.2.2] - November 14, 2018
51
+
52
+ * Improvements to memory usage [#35](https://github.com/imgix/imgix-rb/pull/35)
53
+
54
+ ## [1.2.1] - November 5, 2018
55
+
56
+ * Removed unused `HTTP` dependency [#38](https://github.com/imgix/imgix-rb/pull/37)
57
+
58
+ ## [1.2.0] - October 29, 2018
59
+
60
+ * Added `Client#purge` method to allow purging assets from our cache [#37](https://github.com/imgix/imgix-rb/pull/38)
61
+
62
+ ## [1.1.0] - February 24, 2016
63
+
64
+ * Added automatic Base64 encoding for all Base64 variant parameters.
65
+ * Properly encoding all keys and values output by `Imgix::Path`.
66
+ * Better URL encoding for spaces, with `ERB::Util.url_encode`.
67
+ * Normalize trailing `/` in passed hosts.
68
+
69
+ ## [1.0.0] - December 9, 2015
70
+ ### Changed
71
+ - Removed `Client#sign_path` to provide a consistent method and code path for generating URLs. [#16](https://github.com/imgix/imgix-rb/issues/16)
72
+ - Changed `:secure` option to the more clear `:use_https` [#11](https://github.com/imgix/imgix-rb/issues/11)
73
+ - Changed `:token` option to the more clear `:secure_url_token` [#11](https://github.com/imgix/imgix-rb/issues/11)
74
+
75
+ ### Fixed
76
+ - Fixed URL query strings beginning with `?&s=` instead of `?s=` when no other params are present. [#15](https://github.com/imgix/imgix-rb/issues/15)
77
+
78
+ ## [0.3.3] - May 14, 2015
79
+ ### Fixed
80
+ - Fixed a bug where URLs as the path component for Web Proxy sources would not be encoded would generate URLs that would result in a 400 Bad Request. [#8](https://github.com/imgix/imgix-rb/pull/8)
81
+
82
+ ## [0.3.2] - May 11, 2015
83
+ ### Fixed
84
+ - Fixed a bug where the library would not work if tokens were not present.
@@ -0,0 +1,19 @@
1
+ ## Submitting a Pull Request
2
+
3
+ 1. [Fork the repository.][fork]
4
+ 2. [Create a topic branch.][branch]
5
+ 3. Add tests for your unimplemented feature or bug fix.
6
+ 4. Run `bundle exec rake`. If your tests pass, return to step 3.
7
+ 5. Implement your feature or bug fix.
8
+ 6. Run `bundle exec rake`. If your tests fail, return to step 5.
9
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
10
+ by your tests, return to step 3.
11
+ 8. Add documentation for your feature or bug fix.
12
+ 9. Run `bundle exec rake doc`. If your changes are not 100% documented, go
13
+ back to step 8.
14
+ 10. Add, commit, and push your changes.
15
+ 11. [Submit a pull request.][pr]
16
+
17
+ [fork]: http://help.github.com/fork-a-repo/
18
+ [branch]: http://learn.github.com/p/branching.html
19
+ [pr]: http://help.github.com/send-pull-requests/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imgix.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'minitest'
8
+ gem 'webmock'
9
+ gem 'addressable'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sam Soffes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,258 @@
1
+ <!-- ix-docs-ignore -->
2
+ ![imgix logo](https://assets.imgix.net/sdk-imgix-logo.svg)
3
+
4
+ `imgix-rb` is a client library for generating image URLs with [imgix](https://www.imgix.com/). It is tested under Ruby versions `2.3.0`, `2.2.4`, `2.1.8`, `jruby-9.2.11.0`, and `rbx-3.107`.
5
+
6
+ [![Gem Version](https://img.shields.io/gem/v/imgix.svg)](https://rubygems.org/gems/imgix)
7
+ [![Build Status](https://travis-ci.org/imgix/imgix-rb.svg?branch=main)](https://travis-ci.org/imgix/imgix-rb)
8
+ ![Downloads](https://img.shields.io/gem/dt/imgix)
9
+ [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/imgix/imgix-rb/blob/main/LICENSE)
10
+
11
+ ---
12
+ <!-- /ix-docs-ignore -->
13
+
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [Srcset Generation](#srcset-generation)
17
+ - [Fixed image rendering](#fixed-image-rendering)
18
+ - [Custom Widths](#custom-widths)
19
+ - [Width Tolerance](#width-tolerance)
20
+ - [Minimum and Maximum Width Ranges](#minimum-and-maximum-width-ranges)
21
+ - [Variable Qualities](#variable-qualities)
22
+ - [Multiple Parameters](#multiple-parameters)
23
+ - [Purge Cache](#purge-cache)
24
+ - [URL encoding and signed imgix URLs](#url-encoding-and-signed-imgix-urls)
25
+ - [What is the `ixlib` param on every request?](#what-is-the-ixlib-param-on-every-request)
26
+ - [Contributing](#contributing)
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ``` ruby
33
+ gem 'imgix'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install imgix
43
+
44
+
45
+ ## Usage
46
+
47
+ Initialize a client with a `:domain` and your `:secure_url_token`. By default, HTTPS URLs are generated, but you can toggle that by passing `use_https: false`.
48
+
49
+ Call `Imgix::Client#path` with the resource path to get an `Imgix::Path` object back. You can then manipulate the path parameters, and call `Imgix#Path#to_url` when you're done.
50
+
51
+ ``` ruby
52
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
53
+
54
+ client.path('/images/demo.png').to_url(w: 200)
55
+ #=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
56
+
57
+ # OR
58
+ path = client.path('/images/demo.png')
59
+ path.width = 200
60
+ path.to_url
61
+
62
+ # OR
63
+ client.path('/images/demo.png').width(200).height(300).to_url
64
+
65
+ # Some other tricks
66
+ path.defaults.width(300).to_url # Resets parameters
67
+ path.rect(x: 0, y: 50, width: 200, height: 300).to_url # Rect helper
68
+ ```
69
+
70
+ **Deprecation Notice:** Usage of `:host` has been deprecated and will become invalid in the next major release.
71
+
72
+ In the previous version, `:host` can be used to specify a domain for an `Imgix::Client` like so:
73
+
74
+ ```ruby
75
+ Imgix::Client.new(host: 'demo.imgix.net', secure_url_token: 'token')
76
+ ```
77
+
78
+ Code using `:host` like the above will continue to work until the next major release. While using `:host` will remain valid until the next major release, its usage will result in a deprecation warning. In order to resolve these deprecation warnings before upgrading to the new release, use `:domain` instead of `:host`.
79
+
80
+
81
+ ## Srcset Generation
82
+
83
+ The imgix gem allows for generation of custom `srcset` attributes, which can be invoked through `Imgix::Path#to_srcset`. By default, the `srcset` generated will allow for responsive size switching by building a list of image-width mappings.
84
+
85
+ ```rb
86
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
87
+ path = client.path('/images/demo.png')
88
+
89
+ srcset = path.to_srcset
90
+ ```
91
+
92
+ Will produce the following attribute value, which can then be served to the client:
93
+
94
+ ```html
95
+ https://your-subdomain.imgix.net/images/demo.png?w=100&s=efb3e4ae8eaa1884357f40510b11787c 100w,
96
+ https://your-subdomain.imgix.net/images/demo.png?w=116&s=1417ebeaaaecff39533408cb44893eda 116w,
97
+ https://your-subdomain.imgix.net/images/demo.png?w=134&s=4e45e67c087df930b9ddc8cf5be869d0 134w,
98
+ ...
99
+ https://your-subdomain.imgix.net/images/demo.png?w=7400&s=a5dd7dda1dbac613f0475f1ffd90ef79 7400w,
100
+ https://your-subdomain.imgix.net/images/demo.png?w=8192&s=9fbd257c53e770e345ce3412b64a3452 8192w
101
+ ```
102
+
103
+ ### Fixed image rendering
104
+
105
+ In cases where enough information is provided about an image's dimensions, `to_srcset` 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`, `h`, and `ar`. By invoking `to_srcset` with either a width **or** the height and aspect ratio (along with `fit=crop`, typically) provided, a different `srcset` will be generated for a fixed-size image instead.
106
+
107
+ ```rb
108
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
109
+ path = client.path('/images/demo.png')
110
+
111
+ srcset = path.to_srcset(h:800, ar:'3:2', fit:'crop')
112
+ ```
113
+
114
+ Will produce the following attribute value:
115
+
116
+ ```html
117
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=1&s=f97f2dccf85beac33a3824b57ef4ddc6 1x,
118
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=2&s=e1727167fef53cdb0a89dd66b8672410 2x,
119
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=3&s=7718db8457345419c30214f1d1a3a5d3 3x,
120
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=4&s=000c50a7f97ccdbb9bb2f00bc5241ed4 4x,
121
+ https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=5&s=970b6fc12a410f3dd2959674dd1f4120 5x
122
+ ```
123
+
124
+ 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.
125
+
126
+ ### Custom Widths
127
+
128
+ In situations where specific widths are desired when generating `srcset` pairs, a user can specify them by passing an array of integers via `widths` to the `options` keyword argument.
129
+
130
+ ```rb
131
+ @client ||= Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
132
+ .path('image.jpg')
133
+ .to_srcset(options: { widths: [100, 500, 1000, 1800] })
134
+ ```
135
+
136
+ Will generate the following `srcset` of width pairs:
137
+
138
+ ```html
139
+ https://testing.imgix.net/image.jpg?w=100 100w,
140
+ https://testing.imgix.net/image.jpg?w=500 500w,
141
+ https://testing.imgix.net/image.jpg?w=1000 1000w,
142
+ https://testing.imgix.net/image.jpg?w=1800 1800w
143
+ ```
144
+
145
+ Please note that in situations where a `srcset` is being rendered as a [fixed image](#fixed-image-rendering), any custom `widths` passed in will be ignored. Additionally, if both `widths` and a `width_tolerance` are passed to the `options` parameter in the `to_srcset` method, the custom widths list will take precedence.
146
+
147
+ ### Width Tolerance
148
+
149
+ The `srcset` width tolerance dictates the maximum tolerated size difference between an image's downloaded size and its rendered size. For example: setting this value to 0.1 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 reducing rendering artifacts), 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.
150
+
151
+ By default this rate 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 passing a positive numeric value to `width_tolerance` within the `options` keyword argument:
152
+
153
+ ```rb
154
+ client = Imgix::Client.new(domain: 'testing.imgix.net', secure_url_token: 'MYT0KEN', include_library_param: false)
155
+ client.path('image.jpg').to_srcset(options: { width_tolerance: 0.20 })
156
+ ```
157
+
158
+ In this case, the `width_tolerance` is set to 20 percent, which will be reflected in the difference between subsequent widths in a srcset pair:
159
+
160
+ ```
161
+ https://testing.imgix.net/image.jpg?w=100 100w,
162
+ https://testing.imgix.net/image.jpg?w=140 140w,
163
+ https://testing.imgix.net/image.jpg?w=196 196w,
164
+ ...
165
+ https://testing.imgix.net/image.jpg?w=8192 8192w
166
+ ```
167
+
168
+ ### Minimum and Maximum Width Ranges
169
+
170
+ If the exact number of minimum/maximum physical pixels that an image will need to be rendered at is known, a user can specify them by passing an integer via `min_srcset` and/or `max_srcset` to the `options` keyword parameters:
171
+
172
+ ```rb
173
+ client = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
174
+ client.path('image.jpg').to_srcset(options: { min_srcset: 500, max_srcset: 2000 })
175
+ ```
176
+
177
+ Will result in a smaller, more tailored srcset.
178
+
179
+ ```
180
+ https://testing.imgix.net/image.jpg?w=500 500w,
181
+ https://testing.imgix.net/image.jpg?w=580 580w,
182
+ https://testing.imgix.net/image.jpg?w=672 672w,
183
+ https://testing.imgix.net/image.jpg?w=780 780w,
184
+ https://testing.imgix.net/image.jpg?w=906 906w,
185
+ https://testing.imgix.net/image.jpg?w=1050 1050w,
186
+ https://testing.imgix.net/image.jpg?w=1218 1218w,
187
+ https://testing.imgix.net/image.jpg?w=1414 1414w,
188
+ https://testing.imgix.net/image.jpg?w=1640 1640w,
189
+ https://testing.imgix.net/image.jpg?w=1902 1902w,
190
+ https://testing.imgix.net/image.jpg?w=2000 2000w
191
+ ```
192
+
193
+ Remember that browsers will apply a device pixel ratio as a multiplier when selecting which image to download from a `srcset`. For example, even if you know your image will render no larger than 1000px, specifying `options: { max_srcset: 1000 }` will give your users with DPR higher than 1 no choice but to download and render a low-resolution version of the image. Therefore, it is vital to factor in any potential differences when choosing a minimum or maximum range.
194
+
195
+ Also please note that according to the [imgix API](https://docs.imgix.com/apis/url/size/w), the maximum renderable image width is 8192 pixels.
196
+
197
+ ### Variable Qualities
198
+
199
+ This gem will automatically append a variable `q` parameter mapped to each `dpr` parameter when generating a [fixed-image](https://github.com/imgix/imgix-rb#fixed-image-rendering) srcset. This technique is commonly used to compensate for the increased filesize 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 filesize 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).
200
+
201
+ This behavior will respect any overriding `q` value passed in as a parameter. Additionally, it can be disabled altogether by passing `options: { disable_variable_quality: true }` to `Imgix:Path#to_srcset`.
202
+
203
+ This behavior specifically occurs when a [fixed-size image](https://github.com/imgix/imgix-rb#fixed-image-rendering) is rendered, for example:
204
+
205
+ ```rb
206
+ srcset = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
207
+ .path('image.jpg')
208
+ .to_srcset(w:100)
209
+ ```
210
+
211
+ will generate a srcset with the following `q` to `dpr` mapping:
212
+
213
+ ```html
214
+ https://testing.imgix.net/image.jpg?w=100&dpr=1&q=75 1x,
215
+ https://testing.imgix.net/image.jpg?w=100&dpr=2&q=50 2x,
216
+ https://testing.imgix.net/image.jpg?w=100&dpr=3&q=35 3x,
217
+ https://testing.imgix.net/image.jpg?w=100&dpr=4&q=23 4x,
218
+ https://testing.imgix.net/image.jpg?w=100&dpr=5&q=20 5x
219
+ ```
220
+
221
+ ## Multiple Parameters
222
+
223
+ When the imgix api requires multiple parameters you have to use the method rather than an accessor.
224
+
225
+ For example to use the noise reduction:
226
+
227
+ ``` ruby
228
+ path.noise_reduction(50,50)
229
+ ```
230
+
231
+ ## Purge Cache
232
+
233
+ If you need to remove or update an image on imgix, you can purge it from our cache by initializing a client with your api_key, then calling Imgix::Client#purge with the resource path.
234
+
235
+ ```ruby
236
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', api_key: 'your-key')
237
+ client.purge('/images/demo.png')
238
+ ```
239
+
240
+ To learn more about purging assets with imgix, [see our docs](https://docs.imgix.com/setup/purging-images).
241
+
242
+ ## URL encoding and signed imgix URLs
243
+
244
+ Some important third parties (like Facebook) apply URL escaping to query string components, which can cause correctly signed imgix URLs to to be transformed into incorrectly signed ones. We URL encode the query part of the URL before signing, so you don't have to worry about this.
245
+
246
+ ## What is the `ixlib` param on every request?
247
+
248
+ For security and diagnostic purposes, we sign all requests with the language and version of library used to generate the URL.
249
+
250
+ This can be disabled by including `include_library_param: false` in the instantiation Hash parameter for `Imgix::Client`:
251
+
252
+ ```ruby
253
+ client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', include_library_param: false )
254
+ ```
255
+
256
+ ## Contributing
257
+
258
+ See the [contributing guide](Contributing.markdown).