imgproxy-rails 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b03b90364b582070b6dfbbf0d7b628287286cd3b546096dd5eda2f8bd18ad1c
4
- data.tar.gz: 81718d679156b49ff694b6870903fcb042dee30c93dc29ceab49b3774e233f17
3
+ metadata.gz: a32f1fb8b8e0a6c74771558af38fccbf85f5984e635e7e33bbcfa55803b58aa2
4
+ data.tar.gz: 990e9aec461a9542f596f11379c0c9fc9a33bf4019dd92bd0f142f0c78997601
5
5
  SHA512:
6
- metadata.gz: beec714e3a4d032def537dde78d3f124871e61fa115e5314073c07a2da4e69247ddcd3a901225c1fff7e39395722192d577c3f1db9007072e7bee293f8293f6d
7
- data.tar.gz: 4fd2e8adfa00e4aaaae09a08a62e2ca8e19d7347a0be016eb52157588e0d42dccde7c5fb291480efa03b1c116ab3e6c46afd6a9c446ebef8ac374423059b1707
6
+ metadata.gz: 86cfbf37fbf9108bcb976db31ce1f407378207dc2d687e421e71b5c15dac476acb521d0cdbf704b7492f7591ca23029f88cb9e145a0e72f85d926f276a0709c4
7
+ data.tar.gz: 126fbaf3621c59959fa8e9ff0a82ab1597cd1c5fc0f3667ca04e00b13368c1ab9a3bf39aa6c410f9655d132121fe8b38d7fec61fe45da123ac69653360f7e533
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.2.0 (2023-10-26)
6
+
7
+ - Improved `resize_and_pad` support. ([@palkan][])
8
+
9
+ - Support short URLs for S3/GCS. ([@palkan][])
10
+
5
11
  ## 0.1.0 (2023-09-21)
6
12
 
7
13
  - Initial implementation. ([@Bakaface][])
data/README.md CHANGED
@@ -1,8 +1,22 @@
1
- [![Gem Version](https://badge.fury.io/rb/imgproxy-rails.svg)](https://rubygems.org/gems/imgproxy-rails)
2
- [![Build](https://github.com/palkan/imgproxy-rails/workflows/Build/badge.svg)](https://github.com/palkan/imgproxy-rails/actions)
3
- [![JRuby Build](https://github.com/palkan/imgproxy-rails/workflows/Build%20JRuby/badge.svg)](https://github.com/palkan/imgproxy-rails/actions)
4
-
5
- # imgproxy-rails
1
+ <p align="center">
2
+ <a href="https://imgproxy.net">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/imgproxy/imgproxy/master/assets/logo-dark.svg?sanitize=true">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/imgproxy/imgproxy/master/assets/logo-light.svg?sanitize=true">
6
+ <img alt="imgproxy logo" src="https://raw.githubusercontent.com/imgproxy/imgproxy/master/assets/logo-light.svg?sanitize=true">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/imgproxy/imgproxy-rails/actions"><img alt="GH Test" src="https://img.shields.io/github/actions/workflow/status/imgproxy/imgproxy-rails/rspec.yml?branch=master&label=Test&style=for-the-badge"/></a>
13
+ <a href="https://github.com/imgproxy/imgproxy-rails/actions"><img alt="GH Test Jruby" src="https://img.shields.io/github/actions/workflow/status/imgproxy/imgproxy-rails/rspec-jruby.yml?branch=master&label=Test%20JRuby&style=for-the-badge"/></a>
14
+ <a href="https://github.com/imgproxy/imgproxy-rails/actions"><img alt="GH Lint" src="https://img.shields.io/github/actions/workflow/status/imgproxy/imgproxy-rails/rubocop.yml?branch=master&label=Lint&style=for-the-badge"/></a>
15
+ <a href="https://rubygems.org/gems/imgproxy-rails"><img alt="Gem" src="https://img.shields.io/gem/v/imgproxy-rails.svg?style=for-the-badge"/></a>
16
+ <a href="https://www.rubydoc.info/gems/imgproxy-rails"><img alt="rubydoc.org" src="https://img.shields.io/badge/rubydoc-reference-blue.svg?style=for-the-badge"/></a>
17
+ </p>
18
+
19
+ ---
6
20
 
7
21
  Integration of [imgproxy.rb](https://github.com/imgproxy/imgproxy.rb) with [ActiveStorage::Variant API](https://edgeapi.rubyonrails.org/classes/ActiveStorage/Variant.htmlasses/ActiveStorage/Variant.html).
8
22
 
@@ -64,7 +78,7 @@ Current.user.avatar.variant(resize: "100x100", imgproxy_options: {height: 50, wi
64
78
 
65
79
  ## Contributing
66
80
 
67
- Bug reports and pull requests are welcome on GitHub at [https://github.com/palkan/imgproxy-rails](https://github.com/palkan/imgproxy-rails).
81
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/imgproxy/imgproxy-rails](https://github.com/imgproxy/imgproxy-rails).
68
82
 
69
83
  ## Credits
70
84
 
@@ -8,14 +8,26 @@ module ImgproxyRails
8
8
  {width: width, height: height}
9
9
  end,
10
10
  resize_to_limit: proc { |p| {width: p[0], height: p[1]} },
11
- resize_to_fit: proc { |p| {width: p[0], height: p[1]} },
12
- resize_to_fill: proc { |p| {width: p[0], height: p[1], resizing_type: :fill} },
13
- resize_and_pad: proc { |p, m| resize_and_pad(p, m) },
11
+ resize_to_fit: proc { |p| {width: p[0], height: p[1], enlarge: true} },
12
+ resize_to_fill: proc { |p| {width: p[0], height: p[1], resizing_type: :fill, enlarge: true} },
13
+ resize_and_pad: proc { |p| resize_and_pad(p) },
14
14
  convert: proc { |p| {format: p} },
15
15
  trim: proc { {trim: 0} },
16
16
  modulate: proc { |p| modulate(p) }
17
17
  }.freeze
18
18
 
19
+ GRAVITY = {
20
+ "north" => "no",
21
+ "north-east" => "noea",
22
+ "east" => "ea",
23
+ "south-east" => "soea",
24
+ "south" => "so",
25
+ "south-west" => "sowe",
26
+ "west" => "we",
27
+ "north-west" => "nowe",
28
+ "centre" => "ce"
29
+ }.freeze
30
+
19
31
  PASSTHROUGH_OPTIONS = Set.new([
20
32
  "rotate",
21
33
  "sharpen",
@@ -24,14 +36,14 @@ module ImgproxyRails
24
36
  ]).freeze
25
37
 
26
38
  class << self
27
- def call(transformations, meta)
39
+ def call(transformations)
28
40
  passed_options = transformations.delete(:imgproxy_options) || {}
29
41
  mapped_options = transformations.each_with_object({}) do |(t_key, t_value), memo|
30
42
  if PASSTHROUGH_OPTIONS.include?(t_key.to_s)
31
43
  memo[t_key] = t_value
32
44
  next
33
45
  end
34
- memo.merge!(MAP[t_key].call(t_value, meta)) if MAP.key?(t_key)
46
+ memo.merge!(MAP[t_key].call(t_value)) if MAP.key?(t_key)
35
47
  end
36
48
  mapped_options.merge(passed_options)
37
49
  end
@@ -44,36 +56,20 @@ module ImgproxyRails
44
56
  color.sub(/^#/, "")
45
57
  end
46
58
 
47
- def resize_and_pad(p, m)
59
+ def resize_and_pad(p)
48
60
  target_width, target_height, options = p
49
61
  options ||= {}
50
62
 
51
- result = {width: target_width, height: target_height}
52
- return result unless m["width"] && m["height"]
53
-
54
- aspect_ratio = m["width"].to_f / m["height"]
55
- if aspect_ratio > 1
56
- # add vertical padding
57
- final_height = target_width.to_f / aspect_ratio
58
- padding_length = ((target_height - final_height) / 2).round
59
- result[:padding] = [padding_length, 0]
60
-
61
- # setting min-width for correct upscaling
62
- result[:mw] = target_width
63
- elsif aspect_ratio < 1
64
- # add horizontal padding
65
- final_width = target_height.to_f * aspect_ratio
66
- padding_length = ((target_width - final_width) / 2).round
67
- result[:padding] = [0, padding_length]
68
-
69
- # setting min-height for correct upscaling
70
- result[:mh] = target_height
71
- end
63
+ result = {width: target_width, height: target_height, extend: true}
72
64
 
73
65
  if (background = convert_color(options[:background]))
74
66
  result[:background] = background
75
67
  end
76
68
 
69
+ if (gravity = GRAVITY[options[:gravity].to_s])
70
+ result[:extend] = {extend: true, gravity: gravity}
71
+ end
72
+
77
73
  result
78
74
  end
79
75
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImgproxyRails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgproxy-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-21 00:00:00.000000000 Z
12
+ date: 2023-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: imgproxy
@@ -153,15 +153,15 @@ files:
153
153
  - lib/imgproxy-rails/helpers.rb
154
154
  - lib/imgproxy-rails/transformer.rb
155
155
  - lib/imgproxy-rails/version.rb
156
- homepage: http://github.com/evilmartians/imgproxy-rails
156
+ homepage: http://github.com/imgproxy/imgproxy-rails
157
157
  licenses:
158
158
  - MIT
159
159
  metadata:
160
- bug_tracker_uri: http://github.com/evilmartians/imgproxy-rails/issues
161
- changelog_uri: https://github.com/evilmartians/imgproxy-rails/blob/master/CHANGELOG.md
162
- documentation_uri: http://github.com/evilmartians/imgproxy-rails
163
- homepage_uri: http://github.com/evilmartians/imgproxy-rails
164
- source_code_uri: http://github.com/evilmartians/imgproxy-rails
160
+ bug_tracker_uri: http://github.com/imgproxy/imgproxy-rails/issues
161
+ changelog_uri: https://github.com/imgproxy/imgproxy-rails/blob/master/CHANGELOG.md
162
+ documentation_uri: http://github.com/imgproxy/imgproxy-rails
163
+ homepage_uri: http://github.com/imgproxy/imgproxy-rails
164
+ source_code_uri: http://github.com/imgproxy/imgproxy-rails
165
165
  post_install_message:
166
166
  rdoc_options: []
167
167
  require_paths:
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.4.8
180
+ rubygems_version: 3.4.20
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: integration of imgproxy.rb with ActiveStorage::Variant API