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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21ff1f2f85b91da3ff4348eebce3f2157c7d9f8216afee1c3c8a8264428a390a
4
- data.tar.gz: 8905d951157a918fa7cdd83a33eaf9607423f722dc129bb3f33e888b25697a73
3
+ metadata.gz: 1ebf051e18de9f5e74f9ffc5a3efc716e7e83a3fee7537d28eacd5657fda24f5
4
+ data.tar.gz: fe7e01ce0290adb48269577d295df12661ca029c1a6f9762423e3e8878c3ab2f
5
5
  SHA512:
6
- metadata.gz: 35738982bdb2a55638a975b761973bb04118e80837e0f2850332e5c670ced1d3dd75f1a6079af452e1855d5897ba11b38dcce9f7d97c91e50d513f9fc8ea3dab
7
- data.tar.gz: e4a5b065b76bf44e8ca52480a076364cf37c503d38964d54b9d682395293892243c6fb3d193560ef5c7323288977b87446d0ea879ba302064655dcf2d2cf6219
6
+ metadata.gz: 5df4b176fae56ee6975eb443eba41c68d8fd6941b72199d7264824eba21f980065f598d9794d85832de1f2fdb951636b9c525a868cc7699062883fc993b1973a
7
+ data.tar.gz: d221b89f398e20f8d44116c51e5d565a2d6181d7cb8d046f3e01905630289286b640c52bc8220ad8cfb0bed3c01a8c2c11f4c92070a744cb846bc8f70bd6aff6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imagetools (0.8.0)
4
+ imagetools (0.9.0)
5
5
  rmagick
6
6
 
7
7
  GEM
@@ -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.replace_screenshot_filename(filename)
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 = rename_screenshot(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 rename_screenshot(filepath)
141
+ def rename_image(filepath)
127
142
  fromname = File.basename(filepath)
128
- toname = self.class.replace_screenshot_filename(fromname)
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 = "convert \"#{filepath}\" -background \"#ffffff\" -flatten \"#{topath}\""
178
+ cmd = "#{CONVERT_CMD} \"#{filepath}\" -background \"#ffffff\" -flatten \"#{topath}\""
148
179
  if system(cmd)
149
180
  FileUtils.rm(filepath)
150
181
  end
@@ -1,3 +1,3 @@
1
1
  module Imagetools
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.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: 0.8.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-03 00:00:00.000000000 Z
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick