kamifusen 1.5 → 1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/views/kamifusen/_view.html.erb +33 -11
- data/lib/kamifusen/version.rb +1 -1
- data/lib/kamifusen/view_helper.rb +0 -1
- data/lib/kamifusen.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a82b418d1a07d8b33f845d6ded2bdf3d1309943e41350f8e003bbdcbfe867f08
|
4
|
+
data.tar.gz: 0d20f1c01167036520f1451f1d295d8c7a32d40e315b8ac6fdee707fb3236c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 999758e2fece72df932546f261091b4ffc1584b85668fc9102852d703d4c45526a66ae980ae918f64a6884b99267d2c8c2d3c4646b78a7475ccfd5c01ccf64e0
|
7
|
+
data.tar.gz: be8d74901d1bb3f1859e01e6940c00aa2c9ee67aa086c34fb241de5e5adb510e14a93f39c040ba8dfa8708b1134d7637783775b3a7225cb400575d57643c316c
|
data/Gemfile.lock
CHANGED
@@ -2,11 +2,18 @@
|
|
2
2
|
# image_tag options
|
3
3
|
options ||= {}
|
4
4
|
alt = options[:alt]
|
5
|
-
async = options[:
|
5
|
+
async = options.has_key?(:async) ? options[:async]
|
6
|
+
: true
|
7
|
+
active_storage_direct_url = options.has_key?(:active_storage_direct_url) ? options[:active_storage_direct_url]
|
8
|
+
: false
|
6
9
|
klass = options[:class]
|
7
10
|
picture_class = options[:picture_class]
|
8
11
|
width = options[:width]
|
9
12
|
height = options[:height]
|
13
|
+
|
14
|
+
sizes = Kamifusen.sizes
|
15
|
+
quality = Kamifusen.quality
|
16
|
+
|
10
17
|
if source&.metadata &&
|
11
18
|
source.metadata['analyzed'] &&
|
12
19
|
source.metadata.has_key?('width') &&
|
@@ -16,8 +23,8 @@ if source&.metadata &&
|
|
16
23
|
image_ratio = 1.0 * image_width / image_height
|
17
24
|
if width.nil? && height.nil?
|
18
25
|
# Prendre width et height réelles de l'image
|
19
|
-
width = image_width
|
20
|
-
height =
|
26
|
+
width = [image_width, sizes.last].min
|
27
|
+
height = width * image_ratio
|
21
28
|
elsif width.nil?
|
22
29
|
# Calculer la height sur ratio
|
23
30
|
width = height * image_ratio
|
@@ -34,19 +41,31 @@ if source&.metadata &&
|
|
34
41
|
width = width.round
|
35
42
|
height = height.round
|
36
43
|
end
|
37
|
-
parameters = "
|
38
|
-
parameters
|
44
|
+
parameters = ""
|
45
|
+
parameters += " loading=\"lazy\" decoding=\"async\"" if async
|
39
46
|
parameters += " alt=\"#{ alt }\"" if alt
|
40
47
|
parameters += " width=\"#{ width }\"" if width
|
41
48
|
parameters += " height=\"#{ height }\"" if height
|
42
49
|
parameters += " class=\"#{ klass }\"" if klass
|
50
|
+
|
51
|
+
def kamifusen_process(variant, active_storage_direct_url)
|
52
|
+
if active_storage_direct_url
|
53
|
+
begin
|
54
|
+
# Pour générer la processed url, il faut savoir où sont stockées les images
|
55
|
+
# https://discuss.rubyonrails.org/t/define-host-so-absolute-urls-work-in-development-and-test/75085
|
56
|
+
# https://stackoverflow.com/questions/60425407/uriinvalidurierror-bad-uriis-not-uri-nil-active-storage-service-url
|
57
|
+
# Not compatible with Disk storage, will return nil
|
58
|
+
url = variant.processed.url
|
59
|
+
rescue
|
60
|
+
end
|
61
|
+
end
|
62
|
+
url = url_for(variant) if url.nil?
|
63
|
+
url
|
64
|
+
end
|
43
65
|
%>
|
44
66
|
<% if source.variable? %>
|
45
67
|
<%#= "#{image_width} x #{image_height}, #{image_ratio} ratio => #{width} x #{height}<br>".html_safe %>
|
46
68
|
<%
|
47
|
-
# kamifusen settings
|
48
|
-
sizes = [320, 576, 640, 768, 992, 1152, 1200, 1400, 1536, 1984, 2400]
|
49
|
-
quality = 80
|
50
69
|
# Computing
|
51
70
|
if width
|
52
71
|
width_retina = width * 2
|
@@ -58,13 +77,16 @@ parameters += " class=\"#{ klass }\"" if klass
|
|
58
77
|
default_width = width_retina if width_retina && width_retina > default_width
|
59
78
|
if Kamifusen.with_webp
|
60
79
|
srcset_webp = sizes.map { |size|
|
61
|
-
|
80
|
+
variant = source.variant(resize: "#{size}>", format: :webp, quality: quality)
|
81
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
|
62
82
|
}.join(', ')
|
63
83
|
end
|
64
84
|
srcset_default = sizes.map { |size|
|
65
|
-
|
85
|
+
variant = source.variant(resize: "#{size}>", quality: quality)
|
86
|
+
"#{ kamifusen_process(variant, active_storage_direct_url) } #{ size }w"
|
66
87
|
}.join(', ')
|
67
|
-
|
88
|
+
variant = source.variant(resize: "#{default_width}>", quality: quality)
|
89
|
+
default = kamifusen_process(variant, active_storage_direct_url)
|
68
90
|
%>
|
69
91
|
<picture<%= " class=\"#{picture_class}\"".html_safe unless picture_class.blank? %>>
|
70
92
|
<% if Kamifusen.with_webp %>
|
data/lib/kamifusen/version.rb
CHANGED
data/lib/kamifusen.rb
CHANGED
@@ -9,6 +9,36 @@ module Kamifusen
|
|
9
9
|
mattr_accessor :with_webp
|
10
10
|
@@with_webp = true
|
11
11
|
|
12
|
+
mattr_accessor :sizes
|
13
|
+
@@sizes = [
|
14
|
+
# 360, # Old android
|
15
|
+
375, # Old iPhone
|
16
|
+
# 414, # ?
|
17
|
+
576, # Tablets desktop
|
18
|
+
640, # iPhone SE, some tablets
|
19
|
+
750, # iPhone 6/7/8, 375@2x
|
20
|
+
768, # Old iPads, Old desktops
|
21
|
+
# 828, # ?
|
22
|
+
# 992, # Breakpoint bootstrap
|
23
|
+
1080, # iPhone 6/7/8 plus, 414@2.608 (sorry)
|
24
|
+
# 1125, # iPhone 10, 375@3x
|
25
|
+
1152,
|
26
|
+
# 1172, # iPhone 12, 390@3x
|
27
|
+
1200, # Desktop
|
28
|
+
1366, # Desktop
|
29
|
+
# 1400, # Breakpoint boostrap
|
30
|
+
1440, # Samsung Galaxy S20, 360@4x
|
31
|
+
1536, # Desktop, some iPads
|
32
|
+
1920, # Desktop 2k
|
33
|
+
2048, # Some iPad
|
34
|
+
2240, # Desktop iMac M1 chipset
|
35
|
+
2880, # Desktop MacBook Pro/Air 13" @2x
|
36
|
+
3072 # Desktop MacBook Pro 16" @2x
|
37
|
+
]
|
38
|
+
|
39
|
+
mattr_accessor :quality
|
40
|
+
@@quality = 80
|
41
|
+
|
12
42
|
class Engine < ::Rails::Engine
|
13
43
|
end
|
14
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kamifusen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sébastien Moulène
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-09-
|
12
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|