imgproxy 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +8 -0
- data/CHANGELOG.md +74 -0
- data/README.md +176 -133
- data/UPGRADE.md +136 -0
- data/docs/info_options.md +223 -0
- data/docs/processing_options.md +724 -0
- data/docs/yard/fix_pictures.rb +25 -0
- data/docs/yard/github_alerts.rb +16 -0
- data/docs/yard/relative_markdown_links.rb +31 -0
- data/lib/imgproxy/config.rb +96 -41
- data/lib/imgproxy/extensions/active_storage.rb +6 -4
- data/lib/imgproxy/extensions/shrine.rb +6 -4
- data/lib/imgproxy/option_aliases/info.rb +33 -0
- data/lib/imgproxy/option_aliases/processing.rb +74 -0
- data/lib/imgproxy/options_builders/base.rb +54 -0
- data/lib/imgproxy/options_builders/info.rb +52 -0
- data/lib/imgproxy/options_builders/processing.rb +150 -0
- data/lib/imgproxy/options_casters/adjust.rb +3 -1
- data/lib/imgproxy/options_casters/alpha.rb +27 -0
- data/lib/imgproxy/options_casters/array.rb +3 -1
- data/lib/imgproxy/options_casters/autoquality.rb +28 -0
- data/lib/imgproxy/options_casters/average.rb +27 -0
- data/lib/imgproxy/options_casters/background.rb +27 -0
- data/lib/imgproxy/options_casters/base64.rb +2 -0
- data/lib/imgproxy/options_casters/blur_detections.rb +28 -0
- data/lib/imgproxy/options_casters/blurhash.rb +21 -0
- data/lib/imgproxy/options_casters/bool.rb +3 -1
- data/lib/imgproxy/options_casters/crop.rb +3 -1
- data/lib/imgproxy/options_casters/dominant_colors.rb +27 -0
- data/lib/imgproxy/options_casters/draw_detections.rb +28 -0
- data/lib/imgproxy/options_casters/extend.rb +3 -1
- data/lib/imgproxy/options_casters/filename.rb +31 -0
- data/lib/imgproxy/options_casters/float.rb +4 -2
- data/lib/imgproxy/options_casters/format_quality.rb +19 -0
- data/lib/imgproxy/options_casters/gradient.rb +31 -0
- data/lib/imgproxy/options_casters/gravity.rb +20 -6
- data/lib/imgproxy/options_casters/group.rb +2 -0
- data/lib/imgproxy/options_casters/hashsum.rb +24 -0
- data/lib/imgproxy/options_casters/integer.rb +2 -0
- data/lib/imgproxy/options_casters/jpeg_options.rb +3 -1
- data/lib/imgproxy/options_casters/padding.rb +41 -0
- data/lib/imgproxy/options_casters/png_options.rb +3 -1
- data/lib/imgproxy/options_casters/resize.rb +3 -1
- data/lib/imgproxy/options_casters/size.rb +3 -1
- data/lib/imgproxy/options_casters/string.rb +2 -0
- data/lib/imgproxy/options_casters/trim.rb +3 -1
- data/lib/imgproxy/options_casters/unsharp_masking.rb +25 -0
- data/lib/imgproxy/options_casters/video_thumbnail_tile.rb +34 -0
- data/lib/imgproxy/options_casters/watermark.rb +5 -4
- data/lib/imgproxy/options_casters/watermark_size.rb +21 -0
- data/lib/imgproxy/options_casters/{gif_options.rb → webp_options.rb} +6 -5
- data/lib/imgproxy/options_casters/zoom.rb +27 -0
- data/lib/imgproxy/service_config.rb +111 -0
- data/lib/imgproxy/trim_array.rb +2 -0
- data/lib/imgproxy/url_adapters/active_storage.rb +15 -3
- data/lib/imgproxy/url_adapters/shrine.rb +9 -3
- data/lib/imgproxy/url_adapters.rb +3 -0
- data/lib/imgproxy/url_builders/base.rb +184 -0
- data/lib/imgproxy/url_builders/info.rb +44 -0
- data/lib/imgproxy/url_builders/processing.rb +59 -0
- data/lib/imgproxy/version.rb +3 -1
- data/lib/imgproxy.rb +19 -55
- data/logo/logo-dark.svg +22 -0
- data/logo/logo-light.svg +31 -0
- metadata +74 -35
- data/lib/imgproxy/builder.rb +0 -140
- data/lib/imgproxy/options.rb +0 -115
- data/lib/imgproxy/options_aliases.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0186096d10a3cffb960421a5b8cd53a22525964be29aeed0794e8e2b42159f64'
|
4
|
+
data.tar.gz: a542c12c9f88f7e6caa264312009a686fd793ce3285a6938e0f6edb05fb395c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09a5bcee09b2931b148983b6ab385e7f0dc0725359f31c768a70f6011e7ae5bfe85dcf232bc98a5933ff616392addbfb0aeb65a0fe7220adba5b892689ee3c57'
|
7
|
+
data.tar.gz: b9ad733e0c6d8708009815e7dec8f019fede88454f1b544678a90fd14bacf1df3ed759ad9002a5e73d541b9a9b91cdc85f422047171f504f7f1bf78df1e9d84a
|
data/.yardopts
ADDED
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
|
-
|
2
|
-
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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:
|
138
|
+
user.avatar.imgproxy_url(width: 500, height: 400, resizing_type: :fill)
|
122
139
|
```
|
123
140
|
|
124
|
-
This method will return
|
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
|
-
|
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:
|
175
|
+
user.avatar.imgproxy_url(width: 500, height: 400, resizing_type: :fill)
|
150
176
|
```
|
151
177
|
|
152
|
-
This method will return
|
178
|
+
This method will return a URL to your user's avatar, resized to fill 500x400px on the fly.
|
153
179
|
|
154
|
-
|
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
|
-
|
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
|
-
|
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::
|
231
|
+
builder = Imgproxy::UrlBuilders::Processing.new(
|
185
232
|
width: 500,
|
186
233
|
height: 400,
|
187
234
|
resizing_type: :fill,
|
@@ -190,57 +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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
-
|
200
|
-
-
|
201
|
-
-
|
202
|
-
-
|
203
|
-
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
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
|
-
|
239
|
-
_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.
|
240
267
|
|
241
268
|
### Complex processing options
|
242
269
|
|
243
|
-
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:
|
244
271
|
|
245
272
|
#### Named arguments
|
246
273
|
|
@@ -262,9 +289,11 @@ Imgproxy.url_for(
|
|
262
289
|
# => .../c:500:600:nowe:10:5/...
|
263
290
|
```
|
264
291
|
|
265
|
-
|
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
|
266
295
|
|
267
|
-
You can use named arguments even if the
|
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:
|
268
297
|
|
269
298
|
```ruby
|
270
299
|
Imgproxy.url_for(
|
@@ -284,20 +313,20 @@ Imgproxy.url_for(
|
|
284
313
|
|
285
314
|
#### Unnamed arguments
|
286
315
|
|
287
|
-
The arguments of the complex options can be provided as an array of formatted values
|
316
|
+
The arguments of the complex options can be provided as an array of formatted values:
|
288
317
|
|
289
318
|
```ruby
|
290
319
|
Imgproxy.url_for(
|
291
320
|
"http://images.example.com/images/image.jpg",
|
292
321
|
crop: [500, 600, :nowe, 10, 5],
|
293
|
-
trim: "
|
322
|
+
trim: [10, "aabbcc", 1. 1]
|
294
323
|
)
|
295
324
|
# => .../c:500:600:nowe:10:5/t:10:aabbcc:1:1/...
|
296
325
|
```
|
297
326
|
|
298
327
|
#### Single required argument
|
299
328
|
|
300
|
-
If a complex option has a single required argument, and you don't want to use the optional ones, you can just use
|
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:
|
301
330
|
|
302
331
|
```ruby
|
303
332
|
Imgproxy.url_for(
|
@@ -310,7 +339,7 @@ Imgproxy.url_for(
|
|
310
339
|
|
311
340
|
### Base64 processing options arguments
|
312
341
|
|
313
|
-
Some of the processing options like `watermark_url` or `style` require their arguments to be base64-encoded. Good news is that imgproxy
|
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:
|
314
343
|
|
315
344
|
```ruby
|
316
345
|
Imgproxy.url_for(
|
@@ -321,37 +350,13 @@ Imgproxy.url_for(
|
|
321
350
|
# => .../wmu:aHR0cDovL2V4YW1wbGUuY29tL3dhdGVybWFyay5qcGc/st:Y29sb3I6IHJnYmEoMjU1LCAyNTUsIDI1NSwgLjUp/...
|
322
351
|
```
|
323
352
|
|
324
|
-
### Special options:
|
325
|
-
|
326
|
-
- `base64_encode_url` — per-call redefinition of `base64_encode_urls` config.
|
327
|
-
- `escape_plain_url` — per-call redefinition of `always_escape_plain_urls` config.
|
328
|
-
- `use_short_options` — per-call redefinition of `use_short_options` config.
|
329
|
-
|
330
|
-
## Getting the image info
|
331
|
-
|
332
|
-
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:
|
333
|
-
|
334
|
-
```ruby
|
335
|
-
# Framework-agnositic way
|
336
|
-
Imgproxy.info_url_for("http://images.example.com/images/image.jpg")
|
337
|
-
# Using Active Storage or Shrine
|
338
|
-
user.avatar.imgproxy_info_url
|
339
|
-
|
340
|
-
# You can also use base64_encode_url or escape_plain_url options
|
341
|
-
Imgproxy.info_url_for(
|
342
|
-
"http://images.example.com/images/image.jpg",
|
343
|
-
base64_encode_url: true
|
344
|
-
)
|
345
|
-
Imgproxy.info_url_for(
|
346
|
-
"http://images.example.com/images/image.jpg",
|
347
|
-
escape_plain_url: true
|
348
|
-
)
|
349
|
-
```
|
350
|
-
|
351
353
|
## URL adapters
|
352
354
|
|
353
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.
|
354
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
|
+
|
355
360
|
URL adapter is a simple class that implements `applicable?` and `url` methods. See the example below:
|
356
361
|
|
357
362
|
```ruby
|
@@ -375,15 +380,53 @@ Imgproxy.configure do |config|
|
|
375
380
|
end
|
376
381
|
```
|
377
382
|
|
378
|
-
|
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
|
+
```
|
379
402
|
|
380
|
-
|
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
|
+
```
|
381
424
|
|
382
425
|
## Contributing
|
383
426
|
|
384
427
|
Bug reports and pull requests are welcome on GitHub at https://github.com/imgproxy/imgproxy.rb.
|
385
428
|
|
386
|
-
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://
|
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/.
|
387
430
|
|
388
431
|
## License
|
389
432
|
|
@@ -391,4 +434,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
391
434
|
|
392
435
|
## Security Contact
|
393
436
|
|
394
|
-
To report a security vulnerability, please
|
437
|
+
To report a security vulnerability, please contact us at security@imgproxy.net. We will coordinate the fix and disclosure.
|