imagetools 0.8.0 → 0.9.0
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/Gemfile.lock +1 -1
- data/lib/imagetools/imagefilter.rb +37 -6
- data/lib/imagetools/version.rb +1 -1
- 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: 1ebf051e18de9f5e74f9ffc5a3efc716e7e83a3fee7537d28eacd5657fda24f5
|
4
|
+
data.tar.gz: fe7e01ce0290adb48269577d295df12661ca029c1a6f9762423e3e8878c3ab2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5df4b176fae56ee6975eb443eba41c68d8fd6941b72199d7264824eba21f980065f598d9794d85832de1f2fdb951636b9c525a868cc7699062883fc993b1973a
|
7
|
+
data.tar.gz: d221b89f398e20f8d44116c51e5d565a2d6181d7cb8d046f3e01905630289286b640c52bc8220ad8cfb0bed3c01a8c2c11f4c92070a744cb846bc8f70bd6aff6
|
data/Gemfile.lock
CHANGED
@@ -9,9 +9,17 @@ module Imagetools
|
|
9
9
|
|
10
10
|
SCREENSHOT_SEARCH = /s (\d+)-(\d+)-(\d+) (\d+)\.(\d+)\.(\d+)/
|
11
11
|
SCREENSHOT_REPLACE = 's_\1\2\3_\4\5\6'
|
12
|
+
OTHER_JPG_SEARCH = /\.(large|huge|jpg_large)$/i
|
13
|
+
OTHER_JPG_REPLACE = '.jpg'
|
14
|
+
|
15
|
+
CONVERT_CMD = "convert"
|
16
|
+
DWEBP_CMD = "dwebp"
|
12
17
|
RESIZE_CMD = "mogrify -resize 1280x\\> "
|
13
18
|
COMPRESS_CMD = "jpegoptim --strip-all --max=90 "
|
14
19
|
EXTERNAL_CMDS = [RESIZE_CMD, COMPRESS_CMD]
|
20
|
+
|
21
|
+
WEBP_SEARCH = /(.+)\.webp/i
|
22
|
+
WEBP_REPLACE = '\1.jpg'
|
15
23
|
|
16
24
|
PNG_SEARCH = /(.+)\.png/i
|
17
25
|
PNG_REPLACE = '\1.jpg'
|
@@ -68,10 +76,16 @@ EOM
|
|
68
76
|
filepaths
|
69
77
|
end
|
70
78
|
|
71
|
-
def self.
|
72
|
-
filename.sub!(SCREENSHOT_SEARCH, SCREENSHOT_REPLACE)
|
79
|
+
def self.replace_image_filename(filename)
|
80
|
+
result = filename.sub!(SCREENSHOT_SEARCH, SCREENSHOT_REPLACE)
|
81
|
+
return result if result
|
82
|
+
filename.sub!(OTHER_JPG_SEARCH, OTHER_JPG_REPLACE)
|
73
83
|
end
|
74
84
|
|
85
|
+
def self.replace_webp2jpg(filename)
|
86
|
+
filename.sub!(WEBP_SEARCH, WEBP_REPLACE)
|
87
|
+
end
|
88
|
+
|
75
89
|
def self.replace_png2jpg(filename)
|
76
90
|
filename.sub!(PNG_SEARCH, PNG_REPLACE)
|
77
91
|
end
|
@@ -106,7 +120,8 @@ EOM
|
|
106
120
|
return
|
107
121
|
end
|
108
122
|
|
109
|
-
filepath =
|
123
|
+
filepath = rename_image(filepath)
|
124
|
+
filepath = webp2jpg(filepath)
|
110
125
|
filepath = png2jpg(filepath)
|
111
126
|
filepath = resize_jpg(filepath)
|
112
127
|
filepath = compress_jpg(filepath)
|
@@ -123,9 +138,9 @@ EOM
|
|
123
138
|
false
|
124
139
|
end
|
125
140
|
|
126
|
-
def
|
141
|
+
def rename_image(filepath)
|
127
142
|
fromname = File.basename(filepath)
|
128
|
-
toname = self.class.
|
143
|
+
toname = self.class.replace_image_filename(fromname)
|
129
144
|
return filepath if toname.nil?
|
130
145
|
|
131
146
|
dir = File.dirname(filepath)
|
@@ -135,6 +150,22 @@ EOM
|
|
135
150
|
return topath
|
136
151
|
end
|
137
152
|
|
153
|
+
def webp2jpg(filepath)
|
154
|
+
fromname = File.basename(filepath)
|
155
|
+
toname = self.class.replace_webp2jpg(fromname)
|
156
|
+
return filepath if toname.nil?
|
157
|
+
|
158
|
+
dir = File.dirname(filepath)
|
159
|
+
topath = File.join(dir, toname)
|
160
|
+
puts "convert: #{filepath} => #{topath}"
|
161
|
+
# dwebp ~/Desktop/1.webp -o ~/Desktop/1.jpg
|
162
|
+
cmd = "#{DWEBP_CMD} \"#{filepath}\" -o \"#{topath}\""
|
163
|
+
if system(cmd)
|
164
|
+
FileUtils.rm(filepath)
|
165
|
+
end
|
166
|
+
return topath
|
167
|
+
end
|
168
|
+
|
138
169
|
def png2jpg(filepath)
|
139
170
|
fromname = File.basename(filepath)
|
140
171
|
toname = self.class.replace_png2jpg(fromname)
|
@@ -144,7 +175,7 @@ EOM
|
|
144
175
|
topath = File.join(dir, toname)
|
145
176
|
puts "convert: #{filepath} => #{topath}"
|
146
177
|
# convert test.png -background "#ffff00" -flatten test.jpg
|
147
|
-
cmd = "
|
178
|
+
cmd = "#{CONVERT_CMD} \"#{filepath}\" -background \"#ffffff\" -flatten \"#{topath}\""
|
148
179
|
if system(cmd)
|
149
180
|
FileUtils.rm(filepath)
|
150
181
|
end
|
data/lib/imagetools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagetools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- src
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|