imgproxy 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +8 -0
  3. data/CHANGELOG.md +74 -0
  4. data/README.md +176 -135
  5. data/UPGRADE.md +136 -0
  6. data/docs/info_options.md +223 -0
  7. data/docs/processing_options.md +724 -0
  8. data/docs/yard/fix_pictures.rb +25 -0
  9. data/docs/yard/github_alerts.rb +16 -0
  10. data/docs/yard/relative_markdown_links.rb +31 -0
  11. data/lib/imgproxy/config.rb +96 -41
  12. data/lib/imgproxy/extensions/active_storage.rb +6 -4
  13. data/lib/imgproxy/extensions/shrine.rb +6 -4
  14. data/lib/imgproxy/option_aliases/info.rb +33 -0
  15. data/lib/imgproxy/option_aliases/processing.rb +74 -0
  16. data/lib/imgproxy/options_builders/base.rb +54 -0
  17. data/lib/imgproxy/options_builders/info.rb +52 -0
  18. data/lib/imgproxy/options_builders/processing.rb +150 -0
  19. data/lib/imgproxy/options_casters/adjust.rb +3 -1
  20. data/lib/imgproxy/options_casters/alpha.rb +27 -0
  21. data/lib/imgproxy/options_casters/array.rb +3 -1
  22. data/lib/imgproxy/options_casters/autoquality.rb +28 -0
  23. data/lib/imgproxy/options_casters/average.rb +27 -0
  24. data/lib/imgproxy/options_casters/background.rb +27 -0
  25. data/lib/imgproxy/options_casters/base64.rb +2 -0
  26. data/lib/imgproxy/options_casters/blur_detections.rb +28 -0
  27. data/lib/imgproxy/options_casters/blurhash.rb +21 -0
  28. data/lib/imgproxy/options_casters/bool.rb +3 -1
  29. data/lib/imgproxy/options_casters/crop.rb +3 -1
  30. data/lib/imgproxy/options_casters/dominant_colors.rb +27 -0
  31. data/lib/imgproxy/options_casters/draw_detections.rb +28 -0
  32. data/lib/imgproxy/options_casters/extend.rb +3 -1
  33. data/lib/imgproxy/options_casters/filename.rb +31 -0
  34. data/lib/imgproxy/options_casters/float.rb +3 -1
  35. data/lib/imgproxy/options_casters/format_quality.rb +19 -0
  36. data/lib/imgproxy/options_casters/gradient.rb +31 -0
  37. data/lib/imgproxy/options_casters/gravity.rb +20 -6
  38. data/lib/imgproxy/options_casters/group.rb +2 -0
  39. data/lib/imgproxy/options_casters/hashsum.rb +24 -0
  40. data/lib/imgproxy/options_casters/integer.rb +2 -0
  41. data/lib/imgproxy/options_casters/jpeg_options.rb +3 -1
  42. data/lib/imgproxy/options_casters/padding.rb +41 -0
  43. data/lib/imgproxy/options_casters/png_options.rb +3 -1
  44. data/lib/imgproxy/options_casters/resize.rb +3 -1
  45. data/lib/imgproxy/options_casters/size.rb +3 -1
  46. data/lib/imgproxy/options_casters/string.rb +2 -0
  47. data/lib/imgproxy/options_casters/trim.rb +3 -1
  48. data/lib/imgproxy/options_casters/unsharp_masking.rb +25 -0
  49. data/lib/imgproxy/options_casters/video_thumbnail_tile.rb +34 -0
  50. data/lib/imgproxy/options_casters/watermark.rb +5 -4
  51. data/lib/imgproxy/options_casters/watermark_size.rb +21 -0
  52. data/lib/imgproxy/options_casters/{gif_options.rb → webp_options.rb} +6 -5
  53. data/lib/imgproxy/options_casters/zoom.rb +27 -0
  54. data/lib/imgproxy/service_config.rb +111 -0
  55. data/lib/imgproxy/trim_array.rb +2 -0
  56. data/lib/imgproxy/url_adapters/active_storage.rb +2 -0
  57. data/lib/imgproxy/url_adapters/shrine.rb +8 -2
  58. data/lib/imgproxy/url_adapters.rb +3 -0
  59. data/lib/imgproxy/url_builders/base.rb +184 -0
  60. data/lib/imgproxy/url_builders/info.rb +44 -0
  61. data/lib/imgproxy/url_builders/processing.rb +59 -0
  62. data/lib/imgproxy/version.rb +3 -1
  63. data/lib/imgproxy.rb +19 -57
  64. data/logo/logo-dark.svg +22 -0
  65. data/logo/logo-light.svg +31 -0
  66. metadata +70 -32
  67. data/lib/imgproxy/builder.rb +0 -140
  68. data/lib/imgproxy/options.rb +0 -119
  69. data/lib/imgproxy/options_aliases.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f30666a2a3a8a1097534749a93ca6d53492982f59f43e0fa91553f19957535d8
4
- data.tar.gz: c0ac3bddc82a2e515b728107ad1bc58fedac3eb8edca76532a3f23d8b8def706
3
+ metadata.gz: '0186096d10a3cffb960421a5b8cd53a22525964be29aeed0794e8e2b42159f64'
4
+ data.tar.gz: a542c12c9f88f7e6caa264312009a686fd793ce3285a6938e0f6edb05fb395c1
5
5
  SHA512:
6
- metadata.gz: 3c242a4e67d4e726ebae337e9264454ad223e2fbd31e8f5655cd8a47288e6ab8ee035bebbd0d99dbe17aa9de75ed3fc098cedae1acc7501ac5ea6e3dc43feea7
7
- data.tar.gz: ccd34093cb91dbe50d1a59139db8c94da96fe0f6dba780ae1c1538ccb91646de982055aad509adceb6a3eb6af63f9a2f9af74450ce00aaa6bb0f00439b92acae
6
+ metadata.gz: '09a5bcee09b2931b148983b6ab385e7f0dc0725359f31c768a70f6011e7ae5bfe85dcf232bc98a5933ff616392addbfb0aeb65a0fe7220adba5b892689ee3c57'
7
+ data.tar.gz: b9ad733e0c6d8708009815e7dec8f019fede88454f1b544678a90fd14bacf1df3ed759ad9002a5e73d541b9a9b91cdc85f422047171f504f7f1bf78df1e9d84a
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --asset logo:logo
2
+ --load docs/yard/fix_pictures.rb
3
+ --load docs/yard/relative_markdown_links.rb
4
+ --load docs/yard/github_alerts.rb
5
+ -
6
+ CHANGELOG.md
7
+ UPGRADE.md
8
+ docs/*.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ <!--
2
+ # @title Changelog
3
+ -->
4
+ # Changelog
5
+
6
+ ## [3.0.0] - 2023-12-28
7
+
8
+ ⚠️ This is a major release. See [the migration guide](https://github.com/imgproxy/imgproxy.rb/blob/master/UPGRADE.md). ⚠️
9
+
10
+ ### Added
11
+ - Added info options support.
12
+ - Added missing processing options.
13
+ - Added ecrypted source URLs support.
14
+ - Added extra services support.
15
+
16
+ ## [2.1.0] - 2022-06-14
17
+ ### Added
18
+ - Add `ActiveStorage::Service::MirrorService` support.
19
+ - Add `expires` and `return_attachment` options support.
20
+
21
+ ## [2.0.0] - 2021-03-02
22
+
23
+ ⚠️ This is a major release. See [the migration guide](https://github.com/imgproxy/imgproxy.rb/blob/master/UPGRADE.md). ⚠️
24
+
25
+ ### Added
26
+ - Added missing processing options.
27
+
28
+ ### Changed
29
+ - New processing options format.
30
+ - Active Storage and Shrine extensions are enabled _automagially_.
31
+ - Active Storage and Shrine extensions options are moved to the config.
32
+ - The gem can be configured with environment variables or config files. Thanks to [anyway_config](https://github.com/palkan/anyway_config).
33
+ - Unsupported processing options can be used with some limitations.
34
+ - `hex_key` and `hex_salt` config options are renamed to `key` and `salt`. `key` and `salt` config options are renamed to `raw_key` and `raw_salt`.
35
+
36
+ ## [1.1.0] - 2019-10-14
37
+ ### Added
38
+ - Add crop options;
39
+ - Add adjustment options;
40
+ - Add `pixelate` option;
41
+ - Add `watermark_url` option.
42
+
43
+ ## [1.0.6] - 2019-09-24
44
+ ### Fixed
45
+ - Escape spaces in source URLs;
46
+ - Fix URL combination.
47
+
48
+ ## [1.0.5] - 2019-09-04
49
+ ### Fixed
50
+ - Fix non-ascii URLs support
51
+
52
+ ## [1.0.4] - 2019-08-22
53
+ ### Fixed
54
+ - Only set host to Shrine if it presents
55
+
56
+ ## [1.0.3] - 2019-08-21
57
+ ### Fixed
58
+ - Don't modify builder options
59
+
60
+ ## [1.0.2] - 2019-04-08
61
+ ### Added
62
+ - Add host option to Imgproxy.extend_shrine!
63
+
64
+ ### Changed
65
+ - Check Active Storage attachment service instead of ::ActiveStorage::Blob.service
66
+ - Better URL combination
67
+
68
+ ## [1.0.1] - 2019-04-03
69
+ ### Fixed
70
+ - Fixed URL signing
71
+
72
+ ## [1.0.0] - 2019-04-03
73
+ ### Added
74
+ - First production-ready release
data/README.md CHANGED
@@ -1,21 +1,35 @@
1
- # imgproxy.rb
2
-
3
- <img align="right" width="200" height="200" title="imgproxy logo"
4
- src="https://cdn.rawgit.com/DarthSim/imgproxy/master/logo.svg">
5
-
6
- [![GH Test](https://img.shields.io/github/workflow/status/imgproxy/imgproxy.rb/Test?label=Test&logo=github&style=for-the-badge)](https://github.com/imgproxy/imgproxy.rb/actions) [![GH Lint](https://img.shields.io/github/workflow/status/imgproxy/imgproxy.rb/Lint?label=Lint&logo=github&style=for-the-badge)](https://github.com/imgproxy/imgproxy.rb/actions) [![Gem](https://img.shields.io/gem/v/imgproxy.svg?style=for-the-badge)](https://rubygems.org/gems/imgproxy) [![rubydoc.org](https://img.shields.io/badge/rubydoc-reference-blue.svg?style=for-the-badge)](https://www.rubydoc.info/gems/imgproxy)
7
-
8
- **[imgproxy](https://github.com/imgproxy/imgproxy)** is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, speed, and security. It is a Go application, ready to be installed and used in any Unix environment—also ready to be containerized using Docker.
1
+ <p align="center">
2
+ <a href="https://imgproxy.net">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="logo/logo-dark.svg?sanitize=true">
5
+ <source media="(prefers-color-scheme: light)" srcset="logo/logo-light.svg?sanitize=true">
6
+ <img alt="imgproxy logo" src="logo/logo-light.svg?sanitize=true">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/imgproxy/imgproxy.rb/actions"><img alt="GH Test" src="https://img.shields.io/github/actions/workflow/status/imgproxy/imgproxy.rb/test.yml?branch=master&label=Test&style=for-the-badge"/></a>
13
+ <a href="https://github.com/imgproxy/imgproxy.rb/actions"><img alt="GH Lint" src="https://img.shields.io/github/actions/workflow/status/imgproxy/imgproxy.rb/lint.yml?branch=master&label=Lint&style=for-the-badge"/></a>
14
+ <a href="https://rubygems.org/gems/imgproxy"><img alt="Gem" src="https://img.shields.io/gem/v/imgproxy.svg?style=for-the-badge"/></a>
15
+ <a href="https://www.rubydoc.info/gems/imgproxy"><img alt="rubydoc.org" src="https://img.shields.io/badge/rubydoc-reference-blue.svg?style=for-the-badge"/></a>
16
+ </p>
17
+
18
+ ---
19
+
20
+ [imgproxy](https://imgproxy.net) is a fast and secure standalone server for resizing and converting remote images. The main principles of imgproxy are simplicity, speed, and security. It is a Go application, ready to be installed and used in any Unix environment—also ready to be containerized using Docker.
9
21
 
10
22
  imgproxy can be used to provide a fast and secure way to _get rid of all the image resizing code_ in your web application (like calling ImageMagick or GraphicsMagick, or using libraries), while also being able to resize everything on the fly on a separate server that only you control. imgproxy is fast, easy to use, and requires zero processing power or storage from the main application. imgproxy is indispensable when handling image resizing of epic proportions, especially when original images are coming from a remote source.
11
23
 
12
24
  [imgproxy.rb](https://github.com/imgproxy/imgproxy.rb) is a framework-agnostic Ruby Gem for imgproxy that includes proper support for Ruby on Rails' most popular image attachment options: [Active Storage](https://edgeguides.rubyonrails.org/active_storage_overview.html) and [Shrine](https://github.com/shrinerb/shrine).
13
25
 
14
- **NOTE:** this readme shows documentation for 2.x version. For version 1.x see the [v1.2.0](https://github.com/imgproxy/imgproxy.rb/tree/v1.2.0) tag. See [2.0-Upgrade.md](2.0-Upgrade.md) for the upgrade guide.
15
-
16
- <a href="https://evilmartians.com/?utm_source=imgproxy.rb">
17
- <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
18
- </a>
26
+ > [!IMPORTANT]
27
+ > This readme shows documentation for version 3.x.
28
+ >
29
+ > * For version 2.x see the [v2.1.0](https://github.com/imgproxy/imgproxy.rb/tree/v2.1.0) tag
30
+ > * For version 1.x see the [v1.2.0](https://github.com/imgproxy/imgproxy.rb/tree/v1.2.0) tag
31
+ >
32
+ > See [Upgrading imgproxy.rb](UPGRADE.md) for the upgrade guide.
19
33
 
20
34
  ## Installation
21
35
 
@@ -27,7 +41,7 @@ gem "imgproxy"
27
41
 
28
42
  or install system-wide:
29
43
 
30
- ```
44
+ ```bash
31
45
  gem install imgproxy
32
46
  ```
33
47
 
@@ -35,7 +49,7 @@ gem install imgproxy
35
49
 
36
50
  imgproxy.rb uses [anyway_config](https://github.com/palkan/anyway_config) to load configuration, so you can configure it in different ways.
37
51
 
38
- - With a separate config file:
52
+ With a separate config file:
39
53
 
40
54
  ```yaml
41
55
  # <Rails root>/config/imgproxy.yml
@@ -49,7 +63,7 @@ production: ...
49
63
  test: ...
50
64
  ```
51
65
 
52
- - With a `secrets.yml` entry for imgproxy:
66
+ With a `secrets.yml` entry for imgproxy:
53
67
 
54
68
  ```yaml
55
69
  # secrets.yml
@@ -64,16 +78,16 @@ production:
64
78
  ...
65
79
  ```
66
80
 
67
- - With environment variables:
81
+ With environment variables:
68
82
 
69
83
  ```bash
70
- IMGPROXY_ENDPOINT="http://imgproxy.example.com"\
71
- IMGPROXY_KEY="your_key"\
72
- IMGPROXY_SALT="your_salt"\
84
+ IMGPROXY_ENDPOINT="http://imgproxy.example.com" \
85
+ IMGPROXY_KEY="your_key" \
86
+ IMGPROXY_SALT="your_salt" \
73
87
  rails s
74
88
  ```
75
89
 
76
- - ...or right in your application code:
90
+ ...or right in your application code:
77
91
 
78
92
  ```ruby
79
93
  # config/initializers/imgproxy.rb
@@ -87,21 +101,24 @@ Imgproxy.configure do |config|
87
101
  end
88
102
  ```
89
103
 
90
- #### Configuration options
91
-
92
- - **endpoint** (`IMGPROXY_ENDPOINT`) - Full URL to your imgproxy instance. Default: `nil`.
93
- - **key** (`IMGPROXY_KEY`) - Hex-encoded signature key. Default: `nil`.
94
- - **salt** (`IMGPROXY_SALT`) - Hex-encoded signature salt. Default: `nil`.
95
- - **raw_key** (`IMGPROXY_RAW_KEY`) - Raw (not hex-encoded) signature key. Default: `nil`.
96
- - **raw_salt** (`IMGPROXY_RAW_SALT`) - Raw (not hex-encoded) signature salt. Default: `nil`.
97
- - **signature_size** (`IMGPROXY_SIGNATURE_SIZE`) - Signature size. See [URL signature](https://docs.imgproxy.net/#/configuration?id=url-signature) section of imgproxy docs. Default: 32.
98
- - **use_short_options** (`IMGPROXY_USE_SHORT_OPTIONS`) - Use short processing options names (`rs` for `resize`, `g` for `gravity`, etc). Default: true.
99
- - **base64_encode_urls** (`IMGPROXY_BASE64_ENCODE_URLS`) - Encode source URLs to base64. Default: false.
100
- - **always_escape_plain_urls** (`IMGPROXY_ALWAYS_ESCAPE_PLAIN_URLS`) - Always escape plain source URLs even when ones don't need to be escaped. Default: false.
101
- - **use_s3_urls** (`IMGPROXY_USE_S3_URLS`) - Use `s3://...` source URLs for Active Storage and Shrine attachments stored in Amazon S3. Default: false.
102
- - **use_gcs_urls** (`IMGPROXY_USE_GCS_URLS`) - Use `gs://...` source URLs for Active Storage and Shrine attachments stored in Google Cloud Storage. Default: false.
103
- - **gcs_bucket** (`IMGPROXY_GCS_BUCKET`) - Google Cloud Storage bucket name. Default: `nil`.
104
- - **shrine_host** (`IMGPROXY_SHRINE_HOST`) - Shrine host for locally stored files.
104
+ ### Configuration options
105
+
106
+ * `endpoint` (`IMGPROXY_ENDPOINT`) - Full URL to your imgproxy instance. Default: `nil`.
107
+ * `key` (`IMGPROXY_KEY`) - Hex-encoded signature key. Default: `nil`.
108
+ * `salt` (`IMGPROXY_SALT`) - Hex-encoded signature salt. Default: `nil`.
109
+ * `raw_key` (`IMGPROXY_RAW_KEY`) - Raw (not hex-encoded) signature key. Default: `nil`.
110
+ * `raw_salt` (`IMGPROXY_RAW_SALT`) - Raw (not hex-encoded) signature salt. Default: `nil`.
111
+ * `signature_size` (`IMGPROXY_SIGNATURE_SIZE`) - Signature size. See [URL signature](https://docs.imgproxy.net/configuration/options#url-signature) section of imgproxy docs. Default: 32.
112
+ * `use_short_options` (`IMGPROXY_USE_SHORT_OPTIONS`) - Use short processing options names (`rs` for `resize`, `g` for `gravity`, etc). Default: true.
113
+ * `base64_encode_urls` (`IMGPROXY_BASE64_ENCODE_URLS`) - Encode source URLs to base64. Default: false.
114
+ * `always_escape_plain_urls` (`IMGPROXY_ALWAYS_ESCAPE_PLAIN_URLS`) - Always escape plain source URLs even when ones don't need to be escaped. Default: false.
115
+ * `source_url_encryption_key` (`IMGPROXY_SOURCE_URL_ENCRYPTION_KEY`) - Hex-encoded source URL encryption key. Default: `nil`.
116
+ * `raw_source_url_encryption_key` (`IMGPROXY_RAW_SOURCE_URL_ENCRYPTION_KEY`) - Raw (not hex-encoded) source URL encryption key. Default: `nil`.
117
+ * `always_encrypt_source_urls` (`IMGPROXY_ALWAYS_ENCRYPT_SOURCE_URLS`) - Always encrypt source URLs. Default: false.
118
+ * `use_s3_urls` (`IMGPROXY_USE_S3_URLS`) - Use `s3://...` source URLs for Active Storage and Shrine attachments stored in Amazon S3. Default: false.
119
+ * `use_gcs_urls` (`IMGPROXY_USE_GCS_URLS`) - Use `gs://...` source URLs for Active Storage and Shrine attachments stored in Google Cloud Storage. Default: false.
120
+ * `gcs_bucket` (`IMGPROXY_GCS_BUCKET`) - Google Cloud Storage bucket name. Default: `nil`.
121
+ * `shrine_host` (`IMGPROXY_SHRINE_HOST`) - Shrine host for locally stored files.
105
122
 
106
123
  ## Usage
107
124
 
@@ -118,10 +135,18 @@ Imgproxy.extend_active_storage!
118
135
  Now, to add imgproxy processing to your image attachments, just use the `imgproxy_url` method:
119
136
 
120
137
  ```ruby
121
- user.avatar.imgproxy_url(width: 250, height: 250)
138
+ user.avatar.imgproxy_url(width: 500, height: 400, resizing_type: :fill)
122
139
  ```
123
140
 
124
- This method will return an URL to your user's avatar, resized to 250x250px on the fly.
141
+ This method will return a URL to your user's avatar, resized to fill 500x400px on the fly.
142
+
143
+ If you're a happy user of [imgproxy Pro](https://imgproxy.net#pro), you may find useful it's [Getting an image info](https://docs.imgproxy.net/usage/getting_info) feature. imgproxy.rb allows you to easily generate info URLs for your images:
144
+
145
+ ```ruby
146
+ user.avatar.imgproxy_info_url(detect_objects: true, palette: 128)
147
+ ```
148
+
149
+ This method will return a URL to the JSON with the requested info about your user's avatar.
125
150
 
126
151
  #### Amazon S3
127
152
 
@@ -131,7 +156,8 @@ If you have configured both your imgproxy server and Active Storage to work with
131
156
 
132
157
  You can also enable `gs://...` URLs usage for the files stored in Google Cloud Storage with `use_gcs_urls` and `gcs_bucket` config options (or `IMGPROXY_USE_GCS_URLS` and `IMGPROXY_GCS_BUCKET` env variables).
133
158
 
134
- **NOTE** that you need to explicitly provide GCS bucket name since Active Storage "hides" the GCS config.
159
+ > [!IMPORTANT]
160
+ > You need to explicitly provide GCS bucket name since Active Storage "hides" the GCS config.
135
161
 
136
162
  ### Using with Shrine
137
163
 
@@ -146,19 +172,28 @@ Imgproxy.extend_shrine!
146
172
  Now you can use `imgproxy_url` method of `Shrine::UploadedFile`:
147
173
 
148
174
  ```ruby
149
- user.avatar.imgproxy_url(width: 250, height: 250)
175
+ user.avatar.imgproxy_url(width: 500, height: 400, resizing_type: :fill)
150
176
  ```
151
177
 
152
- This method will return an URL to your user's avatar, resized to 250x250px on the fly.
178
+ This method will return a URL to your user's avatar, resized to fill 500x400px on the fly.
153
179
 
154
- **NOTE:** If you use `Shrine::Storage::FileSystem` as storage, uploaded file URLs won't include the hostname, so imgproxy server won't be able to access them. To fix this, use `shrine_host` config.
180
+ If you're a happy user of [imgproxy Pro](https://imgproxy.net#pro), you may find useful it's [Getting an image info](https://docs.imgproxy.net/usage/getting_info) feature. imgproxy.rb allows you to easily generate info URLs for your images:
155
181
 
156
- Alternatively, you can launch your imgproxy server with the `IMGPROXY_BASE_URL` setting:
157
-
158
- ```
159
- IMGPROXY_BASE_URL="http://your-host.test" imgproxy
182
+ ```ruby
183
+ user.avatar.imgproxy_info_url(detect_objects: true, palette: 128)
160
184
  ```
161
185
 
186
+ This method will return a URL to the JSON with the requested info about your user's avatar.
187
+
188
+ > [!IMPORTANT]
189
+ > If you use `Shrine::Storage::FileSystem` as storage, uploaded file URLs won't include the hostname, so imgproxy server won't be able to access them. To fix this, use `shrine_host` config.
190
+ >
191
+ > Alternatively, you can launch your imgproxy server with the `IMGPROXY_BASE_URL` setting:
192
+ >
193
+ > ```
194
+ > IMGPROXY_BASE_URL="http://your-host.test" imgproxy
195
+ > ```
196
+
162
197
  #### Amazon S3
163
198
 
164
199
  If you have configured both your imgproxy server and Shrine to work with Amazon S3, you can use `use_s3_urls` config option (or `IMGPROXY_USE_S3_URLS` env variable) to make imgproxy.rb use short `s3://...` source URLs instead of long ones generated by Shrine.
@@ -172,16 +207,28 @@ Imgproxy.url_for(
172
207
  "http://images.example.com/images/image.jpg",
173
208
  width: 500,
174
209
  height: 400,
175
- resizing_type: :fill,
176
- sharpen: 0.5
210
+ resizing_type: :fill
211
+ )
212
+ ```
213
+
214
+ This method will return a URL to the image, resized to fill 500x400px on the fly.
215
+
216
+ If you're a happy user of [imgproxy Pro](https://imgproxy.net#pro), you may find useful it's [Getting an image info](https://docs.imgproxy.net/usage/getting_info) feature. imgproxy.rb allows you to easily generate info URLs for your images:
217
+
218
+ ```ruby
219
+ Imgproxy.info_url_for(
220
+ "http://images.example.com/images/image.jpg",
221
+ detect_objects: true,
222
+ palette: 128
177
223
  )
178
- # => http://imgproxy.example.com/2tjGMpWqjO/rs:fill:500:400/sh:0.5/plain/http://images.example.com/images/image.jpg
179
224
  ```
180
225
 
226
+ This method will return a URL to the JSON with the requested info about the image.
227
+
181
228
  You can reuse processing options by using `Imgproxy::Builder`:
182
229
 
183
230
  ```ruby
184
- builder = Imgproxy::Builder.new(
231
+ builder = Imgproxy::UrlBuilders::Processing.new(
185
232
  width: 500,
186
233
  height: 400,
187
234
  resizing_type: :fill,
@@ -190,59 +237,37 @@ builder = Imgproxy::Builder.new(
190
237
 
191
238
  builder.url_for("http://images.example.com/images/image1.jpg")
192
239
  builder.url_for("http://images.example.com/images/image2.jpg")
240
+
241
+ info_builder = Imgproxy::UrlBuilders::Info.new(
242
+ detect_objects: true,
243
+ palette: 128
244
+ )
245
+
246
+ info_builder.url_for("http://images.example.com/images/image1.jpg")
247
+ info_builder.url_for("http://images.example.com/images/image2.jpg")
193
248
  ```
194
249
 
195
- ### Supported imgproxy processing options
196
-
197
- - [resize](https://docs.imgproxy.net/#/generating_the_url_advanced?id=resize)
198
- - [size](https://docs.imgproxy.net/#/generating_the_url_advanced?id=size)
199
- - [resizing_type](https://docs.imgproxy.net/#/generating_the_url_advanced?id=resizing-type)
200
- - [resizing_algorithm](https://docs.imgproxy.net/#/generating_the_url_advanced?id=resizing-algorithm) _(pro)_
201
- - [width](https://docs.imgproxy.net/#/generating_the_url_advanced?id=width)
202
- - [height](https://docs.imgproxy.net/#/generating_the_url_advanced?id=height)
203
- - [dpr](https://docs.imgproxy.net/#/generating_the_url_advanced?id=dpr)
204
- - [enlarge](https://docs.imgproxy.net/#/generating_the_url_advanced?id=enlarge)
205
- - [extend](https://docs.imgproxy.net/#/generating_the_url_advanced?id=extend)
206
- - [gravity](https://docs.imgproxy.net/#/generating_the_url_advanced?id=gravity)
207
- - [crop](https://docs.imgproxy.net/#/generating_the_url_advanced?id=crop)
208
- - [padding](https://docs.imgproxy.net/#/generating_the_url_advanced?id=padding)
209
- - [trim](https://docs.imgproxy.net/#/generating_the_url_advanced?id=trim)
210
- - [rotate](https://docs.imgproxy.net/#/generating_the_url_advanced?id=rotate)
211
- - [quality](https://docs.imgproxy.net/#/generating_the_url_advanced?id=quality)
212
- - [max_bytes](https://docs.imgproxy.net/#/generating_the_url_advanced?id=max-bytes)
213
- - [background](https://docs.imgproxy.net/#/generating_the_url_advanced?id=background)
214
- - [background_alpha](https://docs.imgproxy.net/#/generating_the_url_advanced?id=background-alpha) _(pro)_
215
- - [adjust](https://docs.imgproxy.net/#/generating_the_url_advanced?id=adjust) _(pro)_
216
- - [brightness](https://docs.imgproxy.net/#/generating_the_url_advanced?id=brightness) _(pro)_
217
- - [contrast](https://docs.imgproxy.net/#/generating_the_url_advanced?id=contrast) _(pro)_
218
- - [saturation](https://docs.imgproxy.net/#/generating_the_url_advanced?id=saturation) _(pro)_
219
- - [blur](https://docs.imgproxy.net/#/generating_the_url_advanced?id=blur)
220
- - [sharpen](https://docs.imgproxy.net/#/generating_the_url_advanced?id=sharpen)
221
- - [pixelate](https://docs.imgproxy.net/#/generating_the_url_advanced?id=pixelate) _(pro)_
222
- - [unsharpening](https://docs.imgproxy.net/#/generating_the_url_advanced?id=unsharpening) _(pro)_
223
- - [watermark](https://docs.imgproxy.net/#/generating_the_url_advanced?id=watermark)
224
- - [watermark_url](https://docs.imgproxy.net/#/generating_the_url_advanced?id=watermark-url) _(pro)_
225
- - [style](https://docs.imgproxy.net/#/generating_the_url_advanced?id=style) _(pro)_
226
- - [jpeg_options](https://docs.imgproxy.net/#/generating_the_url_advanced?id=jpeg-options) _(pro)_
227
- - [png_options](https://docs.imgproxy.net/#/generating_the_url_advanced?id=png-options) _(pro)_
228
- - [gif_options](https://docs.imgproxy.net/#/generating_the_url_advanced?id=gif-options) _(pro)_
229
- - [page](https://docs.imgproxy.net/#/generating_the_url_advanced?id=page) _(pro)_
230
- - [video_thumbnail_second](https://docs.imgproxy.net/#/generating_the_url_advanced?id=video-thumbnail-second) _(pro)_
231
- - [preset](https://docs.imgproxy.net/#/generating_the_url_advanced?id=preset)
232
- - [cachebuster](https://docs.imgproxy.net/#/generating_the_url_advanced?id=cachebuster)
233
- - [strip_metadata](https://docs.imgproxy.net/#/generating_the_url_advanced?id=strip-metadata)
234
- - [strip_color_profile](https://docs.imgproxy.net/#/generating_the_url_advanced?id=strip-color-profile)
235
- - [auto_rotate](https://docs.imgproxy.net/#/generating_the_url_advanced?id=auto-rotate)
236
- - [filename](https://docs.imgproxy.net/#/generating_the_url_advanced?id=filename)
237
- - [format](https://docs.imgproxy.net/#/generating_the_url_advanced?id=format)
238
- - [return_attachment](https://docs.imgproxy.net/#/generating_the_url_advanced?id=return-attachment)
239
- - [expires](https://docs.imgproxy.net/#/generating_the_url?id=expires)
240
-
241
- _See [imgproxy URL format guide](https://docs.imgproxy.net/#/generating_the_url_advanced?id=processing-options) for more info._
250
+ ## Supported imgproxy options
251
+
252
+ ### Common options
253
+
254
+ * `base64_encode_url` — per-call redefinition of `base64_encode_urls` config.
255
+ * `escape_plain_url` — per-call redefinition of `always_escape_plain_urls` config.
256
+ * `use_short_options` — per-call redefinition of `use_short_options` config.
257
+ * `encrypt_source_url` - _(pro)_ per-call redefinition of `always_encrypt_source_urls` config.
258
+ * `source_url_encryption_iv` - _(pro)_ an initialization vector (IV) to be used for the source URL encryption if encryption is needed. If not specified, a random IV is used.
259
+
260
+ ### Processing options
261
+
262
+ See [Supported processing options](docs/processing_options.md) for the supported processing options list and their arguments.
263
+
264
+ ### Info options (pro)
265
+
266
+ See [Supported info options](docs/info_options.md) for the supported info options list and their arguments.
242
267
 
243
268
  ### Complex processing options
244
269
 
245
- Some of the processing options like `crop` or `gravity` may have multiple arguments, and you can define these arguments multiple ways:
270
+ Some of the processing and info options like `crop` or `gravity` may have multiple arguments, and you can define these arguments multiple ways:
246
271
 
247
272
  #### Named arguments
248
273
 
@@ -264,9 +289,11 @@ Imgproxy.url_for(
264
289
  # => .../c:500:600:nowe:10:5/...
265
290
  ```
266
291
 
267
- All the arguments have the same names as in [imgproxy documentation](https://docs.imgproxy.net/#/generating_the_url_advanced?id=processing-options).
292
+ You can find argument names on the [Supported processing options](docs/processing_options.md) and [Supported info options](docs/info_options.md) pages.
293
+
294
+ ##### Using named arguments with usupported options
268
295
 
269
- You can use named arguments even if the processing option is not supported by the gem. In this case the arguments won't be reordered nor formatted, so you should provide them in the same order and right the same way they should appear in the URL:
296
+ You can use named arguments even if the option is not supported by the gem. In this case the arguments won't be reordered nor formatted, so you should provide them in the same order and right the same way they should appear in the URL:
270
297
 
271
298
  ```ruby
272
299
  Imgproxy.url_for(
@@ -286,20 +313,20 @@ Imgproxy.url_for(
286
313
 
287
314
  #### Unnamed arguments
288
315
 
289
- The arguments of the complex options can be provided as an array of formatted values or even as a colon-separated string:
316
+ The arguments of the complex options can be provided as an array of formatted values:
290
317
 
291
318
  ```ruby
292
319
  Imgproxy.url_for(
293
320
  "http://images.example.com/images/image.jpg",
294
321
  crop: [500, 600, :nowe, 10, 5],
295
- trim: "10:aabbcc:1:1"
322
+ trim: [10, "aabbcc", 1. 1]
296
323
  )
297
324
  # => .../c:500:600:nowe:10:5/t:10:aabbcc:1:1/...
298
325
  ```
299
326
 
300
327
  #### Single required argument
301
328
 
302
- If a complex option has a single required argument, and you don't want to use the optional ones, you can just use its value:
329
+ If a complex option has a single required argument, and you don't want to use the optional ones, you can just use the required argument value:
303
330
 
304
331
  ```ruby
305
332
  Imgproxy.url_for(
@@ -312,7 +339,7 @@ Imgproxy.url_for(
312
339
 
313
340
  ### Base64 processing options arguments
314
341
 
315
- Some of the processing options like `watermark_url` or `style` require their arguments to be base64-encoded. Good news is that imgproxy gem will encode them for you:
342
+ Some of the processing options like `watermark_url` or `style` require their arguments to be base64-encoded. Good news is that imgproxy.rb will encode them for you:
316
343
 
317
344
  ```ruby
318
345
  Imgproxy.url_for(
@@ -323,37 +350,13 @@ Imgproxy.url_for(
323
350
  # => .../wmu:aHR0cDovL2V4YW1wbGUuY29tL3dhdGVybWFyay5qcGc/st:Y29sb3I6IHJnYmEoMjU1LCAyNTUsIDI1NSwgLjUp/...
324
351
  ```
325
352
 
326
- ### Special options:
327
-
328
- - `base64_encode_url` — per-call redefinition of `base64_encode_urls` config.
329
- - `escape_plain_url` — per-call redefinition of `always_escape_plain_urls` config.
330
- - `use_short_options` — per-call redefinition of `use_short_options` config.
331
-
332
- ## Getting the image info
333
-
334
- If you're a happy user of imgproxy Pro, you may find useful it's [Getting the image info](https://docs.imgproxy.net/#/getting_the_image_info) feature. imgproxy.rb allows you to easily generate info URLs for your images:
335
-
336
- ```ruby
337
- # Framework-agnositic way
338
- Imgproxy.info_url_for("http://images.example.com/images/image.jpg")
339
- # Using Active Storage or Shrine
340
- user.avatar.imgproxy_info_url
341
-
342
- # You can also use base64_encode_url or escape_plain_url options
343
- Imgproxy.info_url_for(
344
- "http://images.example.com/images/image.jpg",
345
- base64_encode_url: true
346
- )
347
- Imgproxy.info_url_for(
348
- "http://images.example.com/images/image.jpg",
349
- escape_plain_url: true
350
- )
351
- ```
352
-
353
353
  ## URL adapters
354
354
 
355
355
  By default, `Imgproxy.url_for` accepts only `String` and `URI` as the source URL, but you can extend that behavior by using URL adapters.
356
356
 
357
+ > [!TIP]
358
+ > imgproxy.rb provides built-in adapters for Active Storage and Shrine that are automatically added when Active Storage or Shrine support is enabled.
359
+
357
360
  URL adapter is a simple class that implements `applicable?` and `url` methods. See the example below:
358
361
 
359
362
  ```ruby
@@ -377,15 +380,53 @@ Imgproxy.configure do |config|
377
380
  end
378
381
  ```
379
382
 
380
- **NOTE:** `Imgproxy` will use the first applicable URL adapter. If you need to add your adapter to the beginning of the list, use the `prepend` method instead of `add`.
383
+ > [!NOTE]
384
+ > `Imgproxy` will use the first applicable URL adapter. If you need to add your adapter to the beginning of the list, use the `prepend` method instead of `add`.
385
+
386
+ ## Extra services
387
+
388
+ If you use more than one instance of imgproxy and they have different endpoints and key/salt configurations you can specify them in `services` option.
389
+
390
+ ```ruby
391
+ Imgproxy.configure do |config|
392
+ config.endpoint = "https://main.imgproxy.com/"
393
+ config.service(:pro) do |pro|
394
+ pro.endpoint = "https://pro.imgproxy.com/"
395
+ pro.key = ENV["IMGPROXY_PRO_KEY"]
396
+ pro.salt = ENV["IMGPROXY_PRO_SALT"]
397
+ pro.source_url_encryption_key = ENV["IMGPROXY_PRO_ENCRYPTION_KEY"]
398
+ pro.always_encrypt_source_urls = true
399
+ end
400
+ end
401
+ ```
381
402
 
382
- **NOTE:** imgproxy.rb provides built-in adapters for Active Storage and Shrine that are automatically added when Active Storage or Shrine support is enabled.
403
+ Or via YAML config:
404
+
405
+ ```yaml
406
+ endpoint: "https://main.imgproxy.com/"
407
+ services:
408
+ pro:
409
+ endpoint: "https://pro.imgproxy.com/"
410
+ key: <%= ENV["IMGPROXY_PRO_KEY"] %>
411
+ salt: <%= ENV["IMGPROXY_PRO_SALT"] %>
412
+ source_url_encryption_key: ENV["IMGPROXY_PRO_ENCRYPTION_KEY"]
413
+ always_encrypt_source_urls: true
414
+ ```
415
+
416
+ If you don't specify `key`, `salt`, `endpoint`, `signature_size`, `source_url_encryption_key`, or `always_encrypt_source_urls`, they are inherited from the global configuration.
417
+
418
+ Pass the `service` option to `url_for` and `info_url_for`:
419
+
420
+ ```ruby
421
+ Imgproxy.url_for(image, service: :pro)
422
+ Imgproxy.info_url_for(image, service: :pro)
423
+ ```
383
424
 
384
425
  ## Contributing
385
426
 
386
427
  Bug reports and pull requests are welcome on GitHub at https://github.com/imgproxy/imgproxy.rb.
387
428
 
388
- If you are having any problems with image processing of imgproxy itself, be sure to visit https://github.com/imgproxy/imgproxy first and check out the docs at https://github.com/imgproxy/imgproxy/blob/master/docs/.
429
+ If you are having any problems with image processing of imgproxy itself, be sure to visit https://github.com/imgproxy/imgproxy first and check out the docs at https://docs.imgproxy.net/.
389
430
 
390
431
  ## License
391
432
 
@@ -393,4 +434,4 @@ The gem is available as open source under the terms of the [MIT License](http://
393
434
 
394
435
  ## Security Contact
395
436
 
396
- To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
437
+ To report a security vulnerability, please contact us at security@imgproxy.net. We will coordinate the fix and disclosure.