alchemy_cloudinary 2.0.1 → 2.0.2

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: cdf1451e1c044e9b6929becb53b69b22bc68646ca752faf2d59d911913237ae5
4
- data.tar.gz: 4767226776526c0d3475bc6b94fe807e5c6985550430bf8ae92cc160e4c2251f
3
+ metadata.gz: 53e24179733979db9d28226655a6389282a338cc7db0bdf726bed4a57b5eca7c
4
+ data.tar.gz: 88e408ddfcf784b048987942315cc65822577c6b1ca6e983d99e55c0ff7b634e
5
5
  SHA512:
6
- metadata.gz: 9c95bcd44c82a6b00ba9ea555bce5b3063778551aecd489dd5a38d63db3bf019493479870e80ee63efbe349f045b693fcb2365f0915ea0139f3c890e067cbda3
7
- data.tar.gz: 04f93a44bc233513fc600a1bb4562b60016e2b6fd41db1c6d0cb13acb8b41d2d37ce7643f20e17587ff909312fb09a8e377b29bd9f8dca6799bd27d7769acc05
6
+ metadata.gz: 233c3e07fa8050610c3c71c3021b1bd5ddaea003d40a4e282ab531a0bed64cdd7a40cffdd63cdc6185c050ca41997e2c65404edd85681f640cd7486eee016a84
7
+ data.tar.gz: f4bb004bfd85c0129b4b537415897092c2535b2f50aeb000208ba179ac5175ef24501abdc493b480c599bdb3d5ca66cf39e7f3cdfae0d972d3659bc15202d4b7
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "alchemy/picture"
4
+
5
+ module Alchemy
6
+ class Picture < BaseRecord
7
+ class CloudinaryUrl < Url
8
+ def call(params = {})
9
+ @options = variant.instance_variable_get(:@options)
10
+
11
+ variant.picture.image_file.remote_url(
12
+ transformation: transformations,
13
+ secure: true,
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :options
20
+
21
+ def transformations
22
+ [crop_transformation, resize_transformation].compact
23
+ end
24
+
25
+ def crop_transformation
26
+ if options[:crop] && options[:crop_from].present?
27
+ {
28
+ crop: "crop",
29
+ gravity: "xy_center",
30
+ x: crop_coordinates[:x],
31
+ y: crop_coordinates[:y],
32
+ size: options[:crop_size],
33
+ }
34
+ end
35
+ end
36
+
37
+ def resize_transformation
38
+ if options[:size]
39
+ {
40
+ crop: crop_mode,
41
+ size: options[:size],
42
+ }
43
+ end
44
+ end
45
+
46
+ def crop_mode
47
+ if options[:crop]
48
+ "fill"
49
+ else
50
+ options[:upsample] ? "fit" : "limit"
51
+ end
52
+ end
53
+
54
+ def crop_coordinates
55
+ x, y = options[:crop_from].to_s.split("x")
56
+ size_x, size_y = options[:crop_size].to_s.split("x")
57
+ {
58
+ x: (x.to_i + size_x.to_f / 2).round,
59
+ y: (y.to_i + size_y.to_f / 2).round,
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AlchemyCloudinary
4
- VERSION = "2.0.1"
4
+ VERSION = "2.0.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy_cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
@@ -53,6 +53,7 @@ extra_rdoc_files: []
53
53
  files:
54
54
  - MIT-LICENSE
55
55
  - README.md
56
+ - app/models/alchemy/picture/cloudinary_url.rb
56
57
  - lib/alchemy_cloudinary.rb
57
58
  - lib/alchemy_cloudinary/create_picture_thumb.rb
58
59
  - lib/alchemy_cloudinary/dragonfly_data_store.rb