rack_image_resizer 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/rack_image_resizer.rb +61 -0
  3. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5bfffa4712aea033e1e8e17def1e465b9134d67ce179f07149d122d3b6d838f4
4
+ data.tar.gz: 173fcb522dd5d12d4fc18b6e29891e79d9babd127a3327913d0f038449232b18
5
+ SHA512:
6
+ metadata.gz: f85c904064c5fc9eff1613dbd28002b464a0fd470124ac9397c2d656a2a6d9c62623b6f210a864d8ba5898103eed49bf6f362315d984881c553296c629e15d67
7
+ data.tar.gz: 22c0a8ee256585c84fe8a49350ddc5d83dccd4aec6282e3f34e9dd02773f4748e458471c617f82a0e72ee8a862d18d6b8b458f59d850c604b741192fdbce9f8c
@@ -0,0 +1,61 @@
1
+ # encodes resized image URLs
2
+
3
+ require 'base64'
4
+
5
+ module ::RackImageResizer
6
+ extend self
7
+
8
+ def resizer_secret
9
+ ENV.fetch('RESIZER_SECRET')
10
+ end
11
+
12
+ def resizer_url
13
+ ENV.fetch('RESIZER_URL')
14
+ end
15
+
16
+ ###
17
+
18
+ # "http://foo.jpg".resize_image({ s: "222x222", q: 80 }
19
+ # "http://foo.jpg".resize_image("^200x200")
20
+ # "http://foo.jpg".resize_image - expcts size as param
21
+ def get opts=nil
22
+ image = opts.delete(:i) || opts.delete(:image)
23
+
24
+ # return empty pixel unless self
25
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" if self.blank?
26
+
27
+ image = image.sub(%r{^(\w+)://}, '')
28
+ prefix = $1 == 'https' ? 's' : 'p'
29
+ image = prefix + image
30
+
31
+ to_encode =
32
+ if opts
33
+ if opts.is_a?(Hash)
34
+ opts[:s] ||= opts.delete(:size) if opts[:size]
35
+ else
36
+ opts = { s: opts }
37
+ end
38
+
39
+ opts[:i] = image
40
+ opts.to_json
41
+ else
42
+ image
43
+ end
44
+
45
+ data = []
46
+
47
+ # add base
48
+ data.push Base64.urlsafe_encode64(to_encode).gsub(/=*\s*$/, '')
49
+
50
+ # add check
51
+ data.push Digest::SHA1.hexdigest(resizer_secret+data.first)[0,4]
52
+
53
+ # add extension
54
+ ext = image.split('.').last.to_s.downcase
55
+ ext = 'jpg' unless ['jpg', 'jpeg', 'gif', 'png', 'svg'].index(ext)
56
+ data.push '.%s' % ext
57
+
58
+ # return full url
59
+ [resizer_url, data.join('')].join('/r/')
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_image_resizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.7
5
+ platform: ruby
6
+ authors:
7
+ - Dino Reic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fast_blank
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ description: Simple and fast ruby image resize server. Image magic in backend, converts
28
+ to webp if possible.
29
+ email: reic.dino@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - "./lib/rack_image_resizer.rb"
35
+ homepage: https://github.com/dux/rack_image_resizer
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.7.5
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Ruby rack image resizer
59
+ test_files: []