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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3b3c82bea2e6142528c1bd2950d328a1a68823f6ae8e0a89f8f69cef33275ed
4
- data.tar.gz: e99f4a964370128a821a0b44c170b39d62b7b18078a7122d6f878a7f67f7cab3
3
+ metadata.gz: e1a3773ab194e825412e9f5cd7a6296b9dae8232b265df6099a1f505662ac21e
4
+ data.tar.gz: e306694b34e778ab2f18f60c55410c3307402f999633a4c288a740468aa181d6
5
5
  SHA512:
6
- metadata.gz: ba4317180125f4d4e31a44666863d40ac2636997ff83211a26bc5e5b99c82e47cc7c5b68a2dff36b94546029fe5a98827ecf14aba4b1c47cb45ee362cdd33243
7
- data.tar.gz: e9bba93211d4a035e6bbeabcd41ad7110ff5bcc4b2daad5512bcfe86bb0dcd9e5932f6e5f8915b765e406167b1de1de4eab5677eeedf2ba7ef720fad6914d6f0
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="304000" />
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="COLUMN_ORDER">
307
+ <option name="COLUMN_ID_ORDER">
311
308
  <list>
312
- <option value="0" />
313
- <option value="2" />
314
- <option value="3" />
315
- <option value="1" />
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imagetools (1.7.0)
4
+ imagetools (1.8.0)
5
5
  rmagick
6
6
 
7
7
  GEM
@@ -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
- WEBP_REPLACE = '\1.webp'
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
- HEIC_REPLACE = '\1.jpg'
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
- # def self.replace_webp2png(filename)
156
- # filename.sub(WEBP_SEARCH, WEBP_REPLACE)
157
- # end
160
+ def self.replace_webp2png(filename)
161
+ filename.sub(WEBP_SEARCH, PNG_REPLACE)
162
+ end
158
163
 
159
- # def self.replace_png2jpg(filename)
160
- # filename.sub(PNG_SEARCH, PNG_REPLACE)
161
- # end
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, HEIC_REPLACE)
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
- # JPEG/PNGをWEBPに変換(WEBPはそのまま)
227
- filepath = image2webp(filepath)
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
- # def webp2png(filepath)
257
- # fromname = File.basename(filepath)
258
- # toname = self.class.replace_webp2png(fromname)
259
- # return filepath if fromname == toname
260
-
261
- # dir = File.dirname(filepath)
262
- # topath = File.join(dir, toname)
263
- # puts "convert: #{filepath} => #{topath}"
264
- # # dwebp ~/Desktop/1.webp -o ~/Desktop/1.jpg
265
- # cmd = "#{DWEBP_CMD} \"#{filepath}\" -o \"#{topath}\""
266
- # if system(cmd)
267
- # FileUtils.rm(filepath)
268
- # end
269
- # return topath
270
- # end
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
- # def png2jpg(filepath)
273
- # fromname = File.basename(filepath)
274
- # toname = self.class.replace_png2jpg(fromname)
275
- # return filepath if fromname == toname
276
-
277
- # dir = File.dirname(filepath)
278
- # topath = File.join(dir, toname)
279
- # puts "convert: #{filepath} => #{topath}"
280
- # # convert test.png -background "#ffff00" -flatten test.jpg
281
- # cmd = "#{CONVERT_CMD} \"#{filepath}\" -background \"#ffffff\" -flatten \"#{topath}\""
282
- # if system(cmd)
283
- # FileUtils.rm(filepath)
284
- # end
285
- # return topath
286
- # end
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
- # def compress_jpg(filepath)
331
- # fromname = File.basename(filepath)
332
- # unless fromname =~ JPG_SEARCH
333
- # return filepath
334
- # end
335
- # puts "compress: #{filepath}"
336
- # cmd = "#{COMPRESS_CMD} \"#{filepath}\""
337
- # system(cmd)
338
- # return filepath
339
- # end
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)
@@ -1,3 +1,3 @@
1
1
  module Imagetools
2
- VERSION = "1.7.0"
2
+ VERSION = "1.8.0"
3
3
  end
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.7.0
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-04-30 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick