alchemy_cloudinary 2.0.1 → 2.0.2
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 +4 -4
- data/app/models/alchemy/picture/cloudinary_url.rb +64 -0
- data/lib/alchemy_cloudinary/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e24179733979db9d28226655a6389282a338cc7db0bdf726bed4a57b5eca7c
|
4
|
+
data.tar.gz: 88e408ddfcf784b048987942315cc65822577c6b1ca6e983d99e55c0ff7b634e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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
|