imagetools 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/workspace.xml +8 -10
- data/Gemfile.lock +1 -1
- data/lib/imagetools/imagefilter.rb +67 -55
- 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: e1a3773ab194e825412e9f5cd7a6296b9dae8232b265df6099a1f505662ac21e
|
4
|
+
data.tar.gz: e306694b34e778ab2f18f60c55410c3307402f999633a4c288a740468aa181d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7939c3704ae59d12664951d529166379ac2029e3104dad8f33987f24f70927cb6c7eca88904ab5a76c2c07cde3e1699f05a1325dbe5e59248056c23b9a9b9cdb
|
7
|
+
data.tar.gz: 90efa73ede00e2712c32c9b05451f22ed0532adbf8ebd6ec02ba495e874d5a4249e44a44865fde03b06085701a583a1bd6c8cc9b214aebdf354f289d14c092f0
|
data/.idea/workspace.xml
CHANGED
@@ -5,13 +5,9 @@
|
|
5
5
|
</component>
|
6
6
|
<component name="ChangeListManager">
|
7
7
|
<list default="true" id="b197c64f-57f8-4389-ab8d-dc9fe3cb05ba" name="Default" comment="">
|
8
|
-
<change beforePath="$PROJECT_DIR$/.idea/runConfigurations.xml" beforeDir="false" />
|
9
8
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
10
|
-
<change beforePath="$PROJECT_DIR$/Gemfile.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Gemfile.lock" afterDir="false" />
|
11
|
-
<change beforePath="$PROJECT_DIR$/imagetools.iml" beforeDir="false" afterPath="$PROJECT_DIR$/imagetools.iml" afterDir="false" />
|
12
9
|
<change beforePath="$PROJECT_DIR$/lib/imagetools/imagefilter.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/imagetools/imagefilter.rb" afterDir="false" />
|
13
10
|
<change beforePath="$PROJECT_DIR$/lib/imagetools/version.rb" beforeDir="false" afterPath="$PROJECT_DIR$/lib/imagetools/version.rb" afterDir="false" />
|
14
|
-
<change beforePath="$PROJECT_DIR$/test/imagefilter_test.rb" beforeDir="false" afterPath="$PROJECT_DIR$/test/imagefilter_test.rb" afterDir="false" />
|
15
11
|
</list>
|
16
12
|
<option name="SHOW_DIALOG" value="false" />
|
17
13
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
@@ -299,7 +295,8 @@
|
|
299
295
|
<workItem from="1669384174219" duration="2215000" />
|
300
296
|
<workItem from="1678251388689" duration="1190000" />
|
301
297
|
<workItem from="1682834450840" duration="2235000" />
|
302
|
-
<workItem from="1682836714784" duration="
|
298
|
+
<workItem from="1682836714784" duration="506000" />
|
299
|
+
<workItem from="1683773814394" duration="2723000" />
|
303
300
|
</task>
|
304
301
|
<servers />
|
305
302
|
</component>
|
@@ -307,12 +304,13 @@
|
|
307
304
|
<option name="version" value="3" />
|
308
305
|
</component>
|
309
306
|
<component name="Vcs.Log.History.Properties">
|
310
|
-
<option name="
|
307
|
+
<option name="COLUMN_ID_ORDER">
|
311
308
|
<list>
|
312
|
-
<option value="
|
313
|
-
<option value="
|
314
|
-
<option value="
|
315
|
-
<option value="
|
309
|
+
<option value="Default.Root" />
|
310
|
+
<option value="Default.Author" />
|
311
|
+
<option value="Default.Date" />
|
312
|
+
<option value="Default.Subject" />
|
313
|
+
<option value="Space.CommitStatus" />
|
316
314
|
</list>
|
317
315
|
</option>
|
318
316
|
</component>
|
data/Gemfile.lock
CHANGED
@@ -71,14 +71,16 @@ module Imagetools
|
|
71
71
|
EXTERNAL_CMDS = [CONVERT_CMD, RESIZE_CMD, ROTATE_CMD, COMPRESS_CMD, DWEBP_CMD, CWEBP_CMD]
|
72
72
|
|
73
73
|
WEBP_SEARCH = /(.+)\.webp/i
|
74
|
-
|
75
|
-
|
74
|
+
|
76
75
|
PNG_SEARCH = /(.+)\.png/i
|
77
|
-
PNG_REPLACE = '\1.jpg'
|
78
76
|
JPG_SEARCH = /(.+)\.jpe?g/i
|
79
77
|
HEIC_SEARCH = /(.+)\.heic/i
|
80
|
-
|
81
|
-
|
78
|
+
|
79
|
+
WEBP_REPLACE = '\1.webp'
|
80
|
+
JPG_REPLACE = '\1.jpg'
|
81
|
+
PNG_REPLACE = '\1.png'
|
82
|
+
|
83
|
+
|
82
84
|
EXCLUDE_PAT = /^_/ # 先頭が"_"の場合は除外
|
83
85
|
|
84
86
|
def self.run(argv)
|
@@ -106,7 +108,10 @@ EOM
|
|
106
108
|
opt.on('-n', '--dry-run', 'Message only') {|v| opts[:n] = v}
|
107
109
|
opt.on('-t', '--self-test', 'Run Self Test') {|v| opts[:t] = v}
|
108
110
|
opt.on('-c', '--config', 'Config file'){|v| opts[:c] = v }
|
111
|
+
types = ['jpg', 'wepp']
|
112
|
+
opt.on('-output-type=OUTPUTTYPE', types, types.join("|") + "(default jpg)") {|v| opts[:o] = v}
|
109
113
|
opt.parse!(argv)
|
114
|
+
opts[:o] ||= types[0]
|
110
115
|
|
111
116
|
config_file = opts[:c] || "~/.imagefilterrc"
|
112
117
|
config_file = File.expand_path(config_file)
|
@@ -152,16 +157,16 @@ EOM
|
|
152
157
|
filename.sub(OTHER_JPG_SEARCH, OTHER_JPG_REPLACE)
|
153
158
|
end
|
154
159
|
|
155
|
-
|
156
|
-
|
157
|
-
|
160
|
+
def self.replace_webp2png(filename)
|
161
|
+
filename.sub(WEBP_SEARCH, PNG_REPLACE)
|
162
|
+
end
|
158
163
|
|
159
|
-
|
160
|
-
|
161
|
-
|
164
|
+
def self.replace_png2jpg(filename)
|
165
|
+
filename.sub(PNG_SEARCH, JPG_REPLACE)
|
166
|
+
end
|
162
167
|
|
163
168
|
def self.replace_heic2jpg(filename)
|
164
|
-
filename.sub(HEIC_SEARCH,
|
169
|
+
filename.sub(HEIC_SEARCH, JPG_REPLACE)
|
165
170
|
end
|
166
171
|
|
167
172
|
def self.replace_image2webp(filename)
|
@@ -222,9 +227,16 @@ EOM
|
|
222
227
|
|
223
228
|
# JPEG/PNG/WEBP 画像のリサイズ
|
224
229
|
filepath = resize_image(filepath)
|
225
|
-
|
226
|
-
|
227
|
-
|
230
|
+
if @opts[:o] == 'webp'
|
231
|
+
# JPEG/PNGをWEBPに変換(WEBPはそのまま)
|
232
|
+
filepath = image2webp(filepath)
|
233
|
+
else
|
234
|
+
# PNGとWebPをJPEGに変換
|
235
|
+
filepath = webp2png(filepath)
|
236
|
+
filepath = png2jpg(filepath)
|
237
|
+
filepath = compress_jpg(filepath)
|
238
|
+
end
|
239
|
+
|
228
240
|
filepath
|
229
241
|
end
|
230
242
|
|
@@ -253,37 +265,37 @@ EOM
|
|
253
265
|
return topath
|
254
266
|
end
|
255
267
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
268
|
+
def webp2png(filepath)
|
269
|
+
fromname = File.basename(filepath)
|
270
|
+
toname = self.class.replace_webp2png(fromname)
|
271
|
+
return filepath if fromname == toname
|
272
|
+
|
273
|
+
dir = File.dirname(filepath)
|
274
|
+
topath = File.join(dir, toname)
|
275
|
+
puts "convert: #{filepath} => #{topath}"
|
276
|
+
# dwebp ~/Desktop/1.webp -o ~/Desktop/1.jpg
|
277
|
+
cmd = "#{DWEBP_CMD} \"#{filepath}\" -o \"#{topath}\""
|
278
|
+
if system(cmd)
|
279
|
+
FileUtils.rm(filepath)
|
280
|
+
end
|
281
|
+
return topath
|
282
|
+
end
|
271
283
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
284
|
+
def png2jpg(filepath)
|
285
|
+
fromname = File.basename(filepath)
|
286
|
+
toname = self.class.replace_png2jpg(fromname)
|
287
|
+
return filepath if fromname == toname
|
288
|
+
|
289
|
+
dir = File.dirname(filepath)
|
290
|
+
topath = File.join(dir, toname)
|
291
|
+
puts "convert: #{filepath} => #{topath}"
|
292
|
+
# convert test.png -background "#ffff00" -flatten test.jpg
|
293
|
+
cmd = "#{CONVERT_CMD} \"#{filepath}\" -background \"#ffffff\" -flatten \"#{topath}\""
|
294
|
+
if system(cmd)
|
295
|
+
FileUtils.rm(filepath)
|
296
|
+
end
|
297
|
+
return topath
|
298
|
+
end
|
287
299
|
|
288
300
|
def heic2jpg(filepath)
|
289
301
|
fromname = File.basename(filepath)
|
@@ -327,16 +339,16 @@ EOM
|
|
327
339
|
return filepath
|
328
340
|
end
|
329
341
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
342
|
+
def compress_jpg(filepath)
|
343
|
+
fromname = File.basename(filepath)
|
344
|
+
unless fromname =~ JPG_SEARCH
|
345
|
+
return filepath
|
346
|
+
end
|
347
|
+
puts "compress: #{filepath}"
|
348
|
+
cmd = "#{COMPRESS_CMD} \"#{filepath}\""
|
349
|
+
system(cmd)
|
350
|
+
return filepath
|
351
|
+
end
|
340
352
|
|
341
353
|
def image2webp(filepath)
|
342
354
|
fromname = File.basename(filepath)
|
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: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- src
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|