imgproxy-rails 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b03b90364b582070b6dfbbf0d7b628287286cd3b546096dd5eda2f8bd18ad1c
4
- data.tar.gz: 81718d679156b49ff694b6870903fcb042dee30c93dc29ceab49b3774e233f17
3
+ metadata.gz: b6974de3a0a3e639db48c61d91831744442c8ac5a5d6e9d4525985896e6b2a01
4
+ data.tar.gz: d081d8571ca8a0cd940839cb97016abf74138158dfe4c0135a45368842c8d007
5
5
  SHA512:
6
- metadata.gz: beec714e3a4d032def537dde78d3f124871e61fa115e5314073c07a2da4e69247ddcd3a901225c1fff7e39395722192d577c3f1db9007072e7bee293f8293f6d
7
- data.tar.gz: 4fd2e8adfa00e4aaaae09a08a62e2ca8e19d7347a0be016eb52157588e0d42dccde7c5fb291480efa03b1c116ab3e6c46afd6a9c446ebef8ac374423059b1707
6
+ metadata.gz: 7ad05883a46086a42ea605d2f978c9f57ef0da2d412b3c2f0443eddc25e62a93727d975459c69299314522e42176435bcbeed20e7b62ea2ba47c24da2bd9d4c1
7
+ data.tar.gz: 177fe43bf90c218934bd705d155bc10812493c8e427d8eed10e81561849d443eacd90c453d6e294655b2307ce165d8dad0b155baf6c790cd2b43f72abf6b7e85
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.3.0 (2023-12-27)
6
+
7
+ - Added support for `video/*` and `application/pdf` content types. ([@DarthSim][])
8
+
9
+ - `config/routes.rb` added to gemspec files ([@chloerei][])
10
+
11
+ ## 0.2.0 (2023-10-26)
12
+
13
+ - Improved `resize_and_pad` support. ([@palkan][])
14
+
15
+ - Support short URLs for S3/GCS. ([@palkan][])
16
+
5
17
  ## 0.1.0 (2023-09-21)
6
18
 
7
19
  - Initial implementation. ([@Bakaface][])
data/README.md CHANGED
@@ -1,10 +1,24 @@
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
6
-
7
- 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).
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
+ ---
20
+
21
+ Integration of [imgproxy.rb](https://github.com/imgproxy/imgproxy.rb) with [ActiveStorage::Variant API](https://edgeapi.rubyonrails.org/classes/ActiveStorage/Variant.html).
8
22
 
9
23
  ## Installation
10
24
 
@@ -62,9 +76,20 @@ You can also specify imgproxy-specific parameters in `imgproxy_options` attribut
62
76
  Current.user.avatar.variant(resize: "100x100", imgproxy_options: {height: 50, width: 50})
63
77
  ```
64
78
 
79
+ ### Generating video and PDF previews
80
+
81
+ If you are an imgproxy Pro user and you want to use it to generate previews for your videos and PDFs, just add their content types to the `variable_content_types` list:
82
+
83
+ ```ruby
84
+ config.active_storage.variable_content_types << "application/pdf"
85
+ config.active_storage.variable_content_types << "video/mp4"
86
+ config.active_storage.variable_content_types << "video/mov"
87
+ # ...etc
88
+ ```
89
+
65
90
  ## Contributing
66
91
 
67
- Bug reports and pull requests are welcome on GitHub at [https://github.com/palkan/imgproxy-rails](https://github.com/palkan/imgproxy-rails).
92
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/imgproxy/imgproxy-rails](https://github.com/imgproxy/imgproxy-rails).
68
93
 
69
94
  ## Credits
70
95
 
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ direct :imgproxy_active_storage do |model, options|
5
+ if ImgproxyRails::Helpers.applicable_variation?(model)
6
+ transformations = model.variation.transformations
7
+ Imgproxy.url_for(model.blob, ImgproxyRails::Transformer.call(transformations))
8
+ else
9
+ route_for(:rails_storage_proxy, model, options)
10
+ end
11
+ end
12
+ end
@@ -2,9 +2,13 @@
2
2
 
3
3
  module ImgproxyRails
4
4
  module Helpers
5
- def self.image_variation?(model)
6
- model.respond_to?(:variation) &&
7
- model.try(:blob)&.content_type&.split("/")&.first == "image"
5
+ def self.applicable_variation?(model)
6
+ return false if !model.respond_to?(:variation)
7
+
8
+ content_type = model.try(:blob)&.content_type
9
+ content_type&.start_with?("image/") ||
10
+ content_type&.start_with?("video/") ||
11
+ content_type == "application/pdf"
8
12
  end
9
13
  end
10
14
  end
@@ -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.3.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.3.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-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: imgproxy
@@ -148,20 +148,21 @@ files:
148
148
  - CHANGELOG.md
149
149
  - LICENSE.txt
150
150
  - README.md
151
+ - config/routes.rb
151
152
  - lib/imgproxy-rails.rb
152
153
  - lib/imgproxy-rails/engine.rb
153
154
  - lib/imgproxy-rails/helpers.rb
154
155
  - lib/imgproxy-rails/transformer.rb
155
156
  - lib/imgproxy-rails/version.rb
156
- homepage: http://github.com/evilmartians/imgproxy-rails
157
+ homepage: http://github.com/imgproxy/imgproxy-rails
157
158
  licenses:
158
159
  - MIT
159
160
  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
161
+ bug_tracker_uri: http://github.com/imgproxy/imgproxy-rails/issues
162
+ changelog_uri: https://github.com/imgproxy/imgproxy-rails/blob/master/CHANGELOG.md
163
+ documentation_uri: http://github.com/imgproxy/imgproxy-rails
164
+ homepage_uri: http://github.com/imgproxy/imgproxy-rails
165
+ source_code_uri: http://github.com/imgproxy/imgproxy-rails
165
166
  post_install_message:
166
167
  rdoc_options: []
167
168
  require_paths:
@@ -177,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubygems_version: 3.4.8
181
+ rubygems_version: 3.3.26
181
182
  signing_key:
182
183
  specification_version: 4
183
184
  summary: integration of imgproxy.rb with ActiveStorage::Variant API