imgix 2.1.0 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +2 -0
- data/.travis.yml +16 -16
- data/.vscode/tasks.json +29 -0
- data/CHANGELOG.md +69 -0
- data/Gemfile +6 -1
- data/README.md +156 -38
- data/Rakefile +2 -0
- data/imgix.gemspec +22 -18
- data/lib/imgix/client.rb +66 -55
- data/lib/imgix/path.rb +197 -45
- data/lib/imgix/version.rb +1 -1
- data/lib/imgix.rb +47 -5
- data/script/bench_path.rb +11 -0
- data/script/bench_to_url.rb +12 -0
- metadata +17 -49
- data/lib/imgix/param_helpers.rb +0 -18
- data/test/test_helper.rb +0 -13
- data/test/units/domains_test.rb +0 -89
- data/test/units/path_test.rb +0 -132
- data/test/units/purge_test.rb +0 -25
- data/test/units/url_test.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ab4780027f2b1f8835f0fe5ad177afbb1ee954f95bd4fa76e92986bb8a31264
|
4
|
+
data.tar.gz: 5c1c49734258dd0c3c99cffa3564d99e140cfede4a6a117a6d3433902a019413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a12613119005a7e9cf84d054b25c459aa6e6cc34e3e9001c11b55e72c3f76ca1566bc4e6737e1891e1445513ae1eb0b8cc247497312937a1a875740b7064afbf
|
7
|
+
data.tar.gz: e9de151e47fa1c555d2199d21539dcb52c27b5879dcb8ece7c822fc96c81f4a7e204a47d73602e349d38728defc38256759d1fb8ad0267369be46d168e0e770e
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
+
dist: trusty
|
1
2
|
language: ruby
|
2
3
|
bundler_args: --without development
|
3
|
-
before_install:
|
4
|
-
# Extracts the ruby version number
|
5
|
-
- RUBY_VERS="$(bc -l<<<$(ruby -v | cut -d' ' -f 2 | cut -d'.' -f 1,2))"
|
6
|
-
# Bundler 2.0 requires at least ruby vers 2.3.0
|
7
|
-
- LATEST_VERS=2.3
|
8
|
-
# Based on a given job's ruby version, install either
|
9
|
-
# Bundler 2.x or 1.17
|
10
|
-
- if (( $(echo "$RUBY_VERS >= $LATEST_VERS" | bc -l) ));
|
11
|
-
then echo $(gem install bundler);
|
12
|
-
else echo $(gem install bundler -v '< 2');
|
13
|
-
fi
|
14
4
|
rvm:
|
15
|
-
- 2.
|
16
|
-
- 2.
|
17
|
-
- 2.
|
18
|
-
|
19
|
-
|
5
|
+
- 2.7
|
6
|
+
- 2.6
|
7
|
+
- jruby-9.2.11.0
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
# Use `fast_finish`, don't wait for any allowed failures.
|
11
|
+
fast_finish: true
|
12
|
+
|
13
|
+
include:
|
14
|
+
- name: Rubinius
|
15
|
+
rvm: rbx-3
|
16
|
+
dist: trusty
|
17
|
+
|
18
|
+
allow_failures:
|
19
|
+
- name: Rubinius
|
data/.vscode/tasks.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"version": "2.0.0",
|
3
|
+
"tasks": [
|
4
|
+
{
|
5
|
+
"label": "rake: test",
|
6
|
+
"type": "shell",
|
7
|
+
"group":{
|
8
|
+
"kind": "test",
|
9
|
+
"isDefault": true
|
10
|
+
},
|
11
|
+
"problemMatcher": {
|
12
|
+
"owner": "ruby",
|
13
|
+
"fileLocation": ["relative", "${workspaceFolder}"],
|
14
|
+
"pattern": [
|
15
|
+
{
|
16
|
+
"regexp": "^([^:]+: .+)",
|
17
|
+
"message": 1
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"regexp": "^ ([^:]+):(\\d+)",
|
21
|
+
"file": 1,
|
22
|
+
"line": 2
|
23
|
+
}
|
24
|
+
]
|
25
|
+
},
|
26
|
+
"command": "bundle exec rake test"
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,75 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [4.0.3](https://github.com/imgix/imgix-rb/compare/4.0.2...4.0.3) - May 05, 2021
|
7
|
+
|
8
|
+
* fix: encode web proxy paths using url_encode ([#111](https://github.com/imgix/imgix-rb/pull/111))
|
9
|
+
|
10
|
+
## [4.0.2](https://github.com/imgix/imgix-rb/compare/4.0.1...4.0.2) - April 22, 2021
|
11
|
+
|
12
|
+
* fix(path): correctly encode reserved chars ([#108](https://github.com/imgix/imgix-rb/pull/108))
|
13
|
+
* test: add benchmark script for Imgix::Path#to_url ([4b00c4b](https://github.com/imgix/imgix-rb/commit/4b00c4b6d27b87787464438b36954b9c166096eb))
|
14
|
+
* perf: avoid calculating path_and_params twice ([#109](https://github.com/imgix/imgix-rb/pull/109))
|
15
|
+
* ci: use major version only for Rubinius 3 ([921e41a](https://github.com/imgix/imgix-rb/commit/921e41ac7789a55c78b42d60ac99cc0b641a69fd))
|
16
|
+
* ci: use optimistic versioning ([#107](https://github.com/imgix/imgix-rb/pull/107))
|
17
|
+
* ci: remove support for ruby version <2.5 ([#106](https://github.com/imgix/imgix-rb/pull/106))
|
18
|
+
* perf: precompute DEFAULT_TARGET_WIDTHS to avoid repeating on Path.new ([#105](https://github.com/imgix/imgix-rb/pull/105))
|
19
|
+
|
20
|
+
## [4.0.1](https://github.com/imgix/imgix-rb/compare/4.0.0...4.0.1) - March 24, 2021
|
21
|
+
|
22
|
+
* fix: dpr srcset when only h param ([#101](https://github.com/imgix/imgix-rb/pull/101))
|
23
|
+
* docs: update travis badge to point to travis-ci.com ([#99](https://github.com/imgix/imgix-rb/pull/99))
|
24
|
+
* docs: fixed typo w/ srcset min/max widths ([#97](https://github.com/imgix/imgix-rb/pull/97))
|
25
|
+
|
26
|
+
## [4.0.0](https://github.com/imgix/imgix-rb/compare/3.4.0...4.0.0) - August 26, 2020
|
27
|
+
|
28
|
+
* deprecate: host-usage, param_helpers, and prefix-1-ary ([#91](https://github.com/imgix/imgix-rb/pull/91))
|
29
|
+
* fix: update purge operation api keys ([#93](https://github.com/imgix/imgix-rb/pull/93))
|
30
|
+
|
31
|
+
## [3.4.0](https://github.com/imgix/imgix-rb/compare/3.3.1...3.4.0) - August 12, 2020
|
32
|
+
|
33
|
+
* fix: deprecate api key versions ([#87](https://github.com/imgix/imgix-rb/pull/87))
|
34
|
+
* docs(readme): deprecation notice for pre-4.0 api keys ([#88](https://github.com/imgix/imgix-rb/pull/88))
|
35
|
+
|
36
|
+
## [3.3.1](https://github.com/imgix/imgix-rb/compare/3.3.0...3.3.1) - July 27, 2020
|
37
|
+
|
38
|
+
* fix: ensure host is initialized ([#82](https://github.com/imgix/imgix-rb/pull/82))
|
39
|
+
|
40
|
+
## [3.3.0](https://github.com/imgix/imgix-rb/compare/3.2.1...3.3.0) - July 21, 2020
|
41
|
+
|
42
|
+
* fix: warn prefix-with-args is deprecated ([#78](https://github.com/imgix/imgix-rb/pull/78))
|
43
|
+
* fix: warn host has been deprecated in favor of domain ([#76](https://github.com/imgix/imgix-rb/pull/76))
|
44
|
+
* fix: deprecate ALIASES and corresponding define_method(s) ([#75](https://github.com/imgix/imgix-rb/pull/75))
|
45
|
+
* fix: deprecate ParamHelpers.rect ([#74](https://github.com/imgix/imgix-rb/pull/74))
|
46
|
+
* fix: allow rbx-3.107 to fail (travis-config) ([#70](https://github.com/imgix/imgix-rb/pull/70))
|
47
|
+
* fix: remove ensure even requirement ([#69](https://github.com/imgix/imgix-rb/pull/69))
|
48
|
+
|
49
|
+
## [3.2.1](https://github.com/imgix/imgix-rb/compare/3.2.0...3.2.1) - November 15, 2019
|
50
|
+
|
51
|
+
* fix: duplicate entries when using `min_width` or `max_width` ([#59](https://github.com/imgix/imgix-rb/pull/59))
|
52
|
+
|
53
|
+
## [3.2.0](https://github.com/imgix/imgix-rb/compare/3.1.1...3.2.0) - November 15, 2019
|
54
|
+
|
55
|
+
* feat: append variable qualities to dpr srcsets ([#58](https://github.com/imgix/imgix-rb/pull/58))
|
56
|
+
* refactor: pass srcset modifiers through the `options` parameter ([#57](https://github.com/imgix/imgix-rb/pull/57))
|
57
|
+
* feat: support defining a min and max width range ([#56](https://github.com/imgix/imgix-rb/pull/56))
|
58
|
+
* feat: add ability to pass in custom widths ([#55](https://github.com/imgix/imgix-rb/pull/55))
|
59
|
+
* feat: add ability to configure the srcset width tolerance ([#54](https://github.com/imgix/imgix-rb/pull/54))
|
60
|
+
* style: drop redundant explicit return statements ([#52](https://github.com/imgix/imgix-rb/pull/52))
|
61
|
+
|
62
|
+
## [3.1.1](https://github.com/imgix/imgix-rb/compare/3.1.0...3.1.1) - July 28, 2019
|
63
|
+
|
64
|
+
* fix: include dpr parameter when generating a DPR srcset ([#48](https://github.com/imgix/imgix-rb/pull/48))
|
65
|
+
* ci(travis): change build dist to trusty and remove bundler script ([#49](https://github.com/imgix/imgix-rb/pull/49))
|
66
|
+
|
67
|
+
## [3.1.0](https://github.com/imgix/imgix-rb/compare/3.0.0...3.1.0) - July 28, 2019
|
68
|
+
|
69
|
+
* feat: add srcset generation ([#47](https://github.com/imgix/imgix-rb/pull/47))
|
70
|
+
|
71
|
+
## [3.0.0](https://github.com/imgix/imgix-rb/compare/2.1.0...3.0.0) - June 7, 2019
|
72
|
+
|
73
|
+
* fix: remove deprecated domain sharding functionality ([#46](https://github.com/imgix/imgix-rb/pull/46))
|
74
|
+
|
6
75
|
## [2.1.0](https://github.com/imgix/imgix-rb/compare/2.0.0...2.1.0) - May 7, 2019
|
7
76
|
|
8
77
|
* Deprecate domain sharding ([#43](https://github.com/imgix/imgix-rb/pull/43)) ([#45](https://github.com/imgix/imgix-rb/pull/45))
|
data/Gemfile
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in imgix.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
8
|
gem 'rake'
|
9
|
+
gem 'json'
|
7
10
|
gem 'minitest'
|
11
|
+
gem 'minitest-reporters'
|
8
12
|
gem 'webmock'
|
9
|
-
gem '
|
13
|
+
gem 'benchmark-ips'
|
14
|
+
|
data/README.md
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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.com/imgix/imgix-rb.svg?branch=main)](https://travis-ci.com/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
|
+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fimgix%2Fimgix-rb.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-rb?ref=badge_shield)
|
11
|
+
|
12
|
+
---
|
13
|
+
<!-- /ix-docs-ignore -->
|
14
|
+
|
15
|
+
- [Installation](#installation)
|
16
|
+
- [Usage](#usage)
|
17
|
+
- [Srcset Generation](#srcset-generation)
|
18
|
+
* [Fixed image rendering](#fixed-image-rendering)
|
19
|
+
* [Custom Widths](#custom-widths)
|
20
|
+
* [Width Tolerance](#width-tolerance)
|
21
|
+
* [Minimum and Maximum Width Ranges](#minimum-and-maximum-width-ranges)
|
22
|
+
* [Variable Qualities](#variable-qualities)
|
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
|
+
- [License](#license)
|
6
28
|
|
7
29
|
## Installation
|
8
30
|
|
@@ -23,78 +45,171 @@ Or install it yourself as:
|
|
23
45
|
|
24
46
|
## Usage
|
25
47
|
|
26
|
-
|
48
|
+
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`.
|
27
49
|
|
28
50
|
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.
|
29
51
|
|
30
|
-
```
|
31
|
-
client = Imgix::Client.new(
|
52
|
+
```rb
|
53
|
+
client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token')
|
32
54
|
|
33
55
|
client.path('/images/demo.png').to_url(w: 200)
|
34
56
|
#=> https://your-subdomain.imgix.net/images/demo.png?w=200&s=2eadddacaa9bba4b88900d245f03f51e
|
57
|
+
```
|
58
|
+
|
59
|
+
## Srcset Generation
|
35
60
|
|
36
|
-
#
|
61
|
+
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.
|
62
|
+
|
63
|
+
```rb
|
64
|
+
client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', secure_url_token: 'your-token', include_library_param: false)
|
37
65
|
path = client.path('/images/demo.png')
|
38
|
-
path.width = 200
|
39
|
-
path.to_url
|
40
66
|
|
41
|
-
|
42
|
-
|
67
|
+
srcset = path.to_srcset
|
68
|
+
```
|
69
|
+
|
70
|
+
Will produce the following attribute value, which can then be served to the client:
|
43
71
|
|
44
|
-
|
45
|
-
|
46
|
-
|
72
|
+
```html
|
73
|
+
https://your-subdomain.imgix.net/images/demo.png?w=100&s=efb3e4ae8eaa1884357f40510b11787c 100w,
|
74
|
+
https://your-subdomain.imgix.net/images/demo.png?w=116&s=1417ebeaaaecff39533408cb44893eda 116w,
|
75
|
+
https://your-subdomain.imgix.net/images/demo.png?w=134&s=4e45e67c087df930b9ddc8cf5be869d0 134w,
|
76
|
+
...
|
77
|
+
https://your-subdomain.imgix.net/images/demo.png?w=7400&s=a5dd7dda1dbac613f0475f1ffd90ef79 7400w,
|
78
|
+
https://your-subdomain.imgix.net/images/demo.png?w=8192&s=9fbd257c53e770e345ce3412b64a3452 8192w
|
47
79
|
```
|
48
80
|
|
81
|
+
### Fixed image rendering
|
49
82
|
|
50
|
-
|
51
|
-
**Warning: Domain Sharding has been deprecated and will be removed in the next major release**<br>
|
52
|
-
To find out more, see our [blog post](https://blog.imgix.com/2019/05/03/deprecating-domain-sharding) explaining the decision to remove this feature.
|
83
|
+
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` or `h`. By invoking `to_srcset` with either a width **or** height provided, a different `srcset` will be generated for a fixed-size image instead.
|
53
84
|
|
54
|
-
|
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')
|
55
88
|
|
56
|
-
|
89
|
+
srcset = path.to_srcset(h:800, ar:'3:2', fit:'crop')
|
90
|
+
```
|
57
91
|
|
92
|
+
Will produce the following attribute value:
|
58
93
|
|
59
|
-
```
|
60
|
-
|
61
|
-
|
94
|
+
```html
|
95
|
+
https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=1&s=f97f2dccf85beac33a3824b57ef4ddc6 1x,
|
96
|
+
https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=2&s=e1727167fef53cdb0a89dd66b8672410 2x,
|
97
|
+
https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=3&s=7718db8457345419c30214f1d1a3a5d3 3x,
|
98
|
+
https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=4&s=000c50a7f97ccdbb9bb2f00bc5241ed4 4x,
|
99
|
+
https://your-subdomain.imgix.net/images/demo.png?h=800&ar=3%3A2&fit=crop&dpr=5&s=970b6fc12a410f3dd2959674dd1f4120 5x
|
62
100
|
```
|
63
101
|
|
64
|
-
|
102
|
+
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.
|
65
103
|
|
104
|
+
### Custom Widths
|
66
105
|
|
67
|
-
|
68
|
-
|
69
|
-
|
106
|
+
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.
|
107
|
+
|
108
|
+
```rb
|
109
|
+
@client ||= Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
|
110
|
+
.path('image.jpg')
|
111
|
+
.to_srcset(options: { widths: [100, 500, 1000, 1800] })
|
70
112
|
```
|
71
113
|
|
114
|
+
Will generate the following `srcset` of width pairs:
|
72
115
|
|
73
|
-
|
116
|
+
```html
|
117
|
+
https://testing.imgix.net/image.jpg?w=100 100w,
|
118
|
+
https://testing.imgix.net/image.jpg?w=500 500w,
|
119
|
+
https://testing.imgix.net/image.jpg?w=1000 1000w,
|
120
|
+
https://testing.imgix.net/image.jpg?w=1800 1800w
|
121
|
+
```
|
74
122
|
|
75
|
-
|
123
|
+
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.
|
76
124
|
|
77
|
-
|
125
|
+
### Width Tolerance
|
126
|
+
|
127
|
+
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.
|
128
|
+
|
129
|
+
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:
|
130
|
+
|
131
|
+
```rb
|
132
|
+
client = Imgix::Client.new(domain: 'testing.imgix.net', secure_url_token: 'MYT0KEN', include_library_param: false)
|
133
|
+
client.path('image.jpg').to_srcset(options: { width_tolerance: 0.20 })
|
134
|
+
```
|
135
|
+
|
136
|
+
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:
|
78
137
|
|
79
|
-
``` ruby
|
80
|
-
path.noise_reduction(50,50)
|
81
138
|
```
|
139
|
+
https://testing.imgix.net/image.jpg?w=100 100w,
|
140
|
+
https://testing.imgix.net/image.jpg?w=140 140w,
|
141
|
+
https://testing.imgix.net/image.jpg?w=196 196w,
|
142
|
+
...
|
143
|
+
https://testing.imgix.net/image.jpg?w=8192 8192w
|
144
|
+
```
|
145
|
+
|
146
|
+
### Minimum and Maximum Width Ranges
|
147
|
+
|
148
|
+
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_width` and/or `max_width` to the `options` keyword parameters:
|
149
|
+
|
150
|
+
```rb
|
151
|
+
client = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
|
152
|
+
client.path('image.jpg').to_srcset(options: { min_width: 500, max_width: 2000 })
|
153
|
+
```
|
154
|
+
|
155
|
+
Will result in a smaller, more tailored srcset.
|
156
|
+
|
157
|
+
```
|
158
|
+
https://testing.imgix.net/image.jpg?w=500 500w,
|
159
|
+
https://testing.imgix.net/image.jpg?w=580 580w,
|
160
|
+
https://testing.imgix.net/image.jpg?w=672 672w,
|
161
|
+
https://testing.imgix.net/image.jpg?w=780 780w,
|
162
|
+
https://testing.imgix.net/image.jpg?w=906 906w,
|
163
|
+
https://testing.imgix.net/image.jpg?w=1050 1050w,
|
164
|
+
https://testing.imgix.net/image.jpg?w=1218 1218w,
|
165
|
+
https://testing.imgix.net/image.jpg?w=1414 1414w,
|
166
|
+
https://testing.imgix.net/image.jpg?w=1640 1640w,
|
167
|
+
https://testing.imgix.net/image.jpg?w=1902 1902w,
|
168
|
+
https://testing.imgix.net/image.jpg?w=2000 2000w
|
169
|
+
```
|
170
|
+
|
171
|
+
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_width: 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.
|
82
172
|
|
173
|
+
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.
|
174
|
+
|
175
|
+
### Variable Qualities
|
176
|
+
|
177
|
+
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).
|
178
|
+
|
179
|
+
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`.
|
180
|
+
|
181
|
+
This behavior specifically occurs when a [fixed-size image](https://github.com/imgix/imgix-rb#fixed-image-rendering) is rendered, for example:
|
182
|
+
|
183
|
+
```rb
|
184
|
+
srcset = Imgix::Client.new(domain: 'testing.imgix.net', include_library_param: false)
|
185
|
+
.path('image.jpg')
|
186
|
+
.to_srcset(w:100)
|
187
|
+
```
|
188
|
+
|
189
|
+
will generate a srcset with the following `q` to `dpr` mapping:
|
190
|
+
|
191
|
+
```html
|
192
|
+
https://testing.imgix.net/image.jpg?w=100&dpr=1&q=75 1x,
|
193
|
+
https://testing.imgix.net/image.jpg?w=100&dpr=2&q=50 2x,
|
194
|
+
https://testing.imgix.net/image.jpg?w=100&dpr=3&q=35 3x,
|
195
|
+
https://testing.imgix.net/image.jpg?w=100&dpr=4&q=23 4x,
|
196
|
+
https://testing.imgix.net/image.jpg?w=100&dpr=5&q=20 5x
|
197
|
+
```
|
83
198
|
|
84
199
|
## Purge Cache
|
85
200
|
|
86
|
-
If you need to remove or update an image on imgix, you can purge it from our cache by initializing a client with your
|
201
|
+
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](http://dashboard.imgix.com/api-keys), then calling `Imgix::Client#purge` with the resource path.
|
87
202
|
|
88
203
|
```ruby
|
89
|
-
client = Imgix::Client.new(
|
204
|
+
client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', api_key: 'your-key')
|
90
205
|
client.purge('/images/demo.png')
|
91
206
|
```
|
92
207
|
|
93
208
|
To learn more about purging assets with imgix, [see our docs](https://docs.imgix.com/setup/purging-images).
|
94
209
|
|
95
|
-
## URL encoding and signed
|
210
|
+
## URL encoding and signed imgix URLs
|
96
211
|
|
97
|
-
Some important third parties (like Facebook) apply URL escaping to query string components, which can cause correctly signed
|
212
|
+
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.
|
98
213
|
|
99
214
|
## What is the `ixlib` param on every request?
|
100
215
|
|
@@ -103,9 +218,12 @@ For security and diagnostic purposes, we sign all requests with the language and
|
|
103
218
|
This can be disabled by including `include_library_param: false` in the instantiation Hash parameter for `Imgix::Client`:
|
104
219
|
|
105
220
|
```ruby
|
106
|
-
client = Imgix::Client.new(
|
221
|
+
client = Imgix::Client.new(domain: 'your-subdomain.imgix.net', include_library_param: false )
|
107
222
|
```
|
108
223
|
|
109
224
|
## Contributing
|
110
225
|
|
111
226
|
See the [contributing guide](Contributing.markdown).
|
227
|
+
|
228
|
+
## License
|
229
|
+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fimgix%2Fimgix-rb.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fimgix%2Fimgix-rb?ref=badge_large)
|
data/Rakefile
CHANGED
data/imgix.gemspec
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
require 'imgix/version'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/imgix/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = "imgix"
|
8
7
|
spec.version = Imgix::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
8
|
+
spec.authors = ["Kelly Sutton", "Sam Soffes", "Ryan LeFevre", "Antony Denyer", "Paul Straw", "Sherwin Heydarbeygi"]
|
9
|
+
spec.email = ["kelly@imgix.com", "sam@soff.es", "ryan@layervault.com", "email@antonydenyer.co.uk", "paul@imgix.com", "sherwin@imgix.com"]
|
10
|
+
spec.description = "Easily create and sign imgix URLs."
|
11
|
+
spec.summary = "Official Ruby Gem for easily creating and signing imgix URLs."
|
12
|
+
spec.homepage = "https://github.com/imgix/imgix-rb"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.metadata = {
|
16
|
+
"bug_tracker_uri" => "https://github.com/imgix/imgix-rb/issues",
|
17
|
+
"changelog_uri" => "https://github.com/imgix/imgix-rb/blob/main/CHANGELOG.md",
|
18
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/imgix/#{spec.version}",
|
19
|
+
"source_code_uri" => "https://github.com/imgix/imgix-rb/tree/#{spec.version}"
|
20
|
+
}
|
15
21
|
|
16
|
-
spec.files =
|
17
|
-
|
18
|
-
|
19
|
-
spec.require_paths = ['lib']
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.github)/}) }
|
24
|
+
end
|
20
25
|
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.add_development_dependency 'webmock'
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.required_ruby_version = ">= 1.9.0"
|
24
28
|
end
|