imagetools 1.1.0 → 1.4.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: 4321ff7a51cd2038d5acb37c21c932d40ce0eb0e7a0f2514e852dd7c36e26617
4
- data.tar.gz: dc47c8f323837468154686fed41727a9096560bed0ca0cb00e1f62b675ba44f6
3
+ metadata.gz: c695900493f7e008bd7a71202f740d8cf7934017cc4dbd554102e52c45d68be5
4
+ data.tar.gz: 9d0085886aac557e3da673d47258a30bf5c8ebcee4d77ad641ce232e73c21bb1
5
5
  SHA512:
6
- metadata.gz: e8383d80757e294e21277deade67ee1b05b1760918b3b2ef6b76478959244a6b1b39e682630b68b876f87371121df9cc4dc8a6a0db5954bda84ab61346b8101a
7
- data.tar.gz: 0a69d98a867405f44dccf7406cc1cd9a9a1e82b2eb2bf5eb979e284ea89aa28878118a75df83ff6e8c36e44b559b6d795fa00aab7ff1198655e1549f65a36da2
6
+ metadata.gz: 9a0c730e84290e6f18afa19c5446d98e75fee8a2966229812d7e372e6e3dd9e38909c5f6c447ef8af9c807645b936248b50086709cce7f7df301e02536b60aef
7
+ data.tar.gz: c3e99d26db139acc25fc259449e6ba7344c9e788bd595ad6744a408ff7e5da253d07f00dc0a57a8036e464dc8c6f3763f07327fb137dddfd2be49f7aa37bcadb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.7.5
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imagetools (1.1.0)
4
+ imagetools (1.4.0)
5
5
  rmagick (= 3.2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- minitest (5.14.0)
11
- rake (13.0.1)
10
+ minitest (5.15.0)
11
+ rake (13.0.6)
12
12
  rmagick (3.2.0)
13
13
 
14
14
  PLATFORMS
@@ -21,4 +21,4 @@ DEPENDENCIES
21
21
  rake (~> 13.0)
22
22
 
23
23
  BUNDLED WITH
24
- 2.0.2
24
+ 2.1.4
@@ -44,22 +44,26 @@ module Imagetools
44
44
  end
45
45
 
46
46
  class Imagefilter
47
- OTHER_JPG_SEARCH = /\.(large|huge|jpg_large)$/i
47
+ OTHER_JPG_SEARCH = /\.(large|huge|jpg_large|JPG)$/i
48
48
  OTHER_JPG_REPLACE = '.jpg'
49
49
 
50
50
  CONVERT_CMD = "convert"
51
51
  DWEBP_CMD = "dwebp"
52
- RESIZE_CMD = "mogrify -resize 1280x\\> "
52
+ # RESIZE_CMD = "mogrify -resize 1280x\\> "
53
+ RESIZE_CMD = "mogrify -background white -resize 1280x\\> "
53
54
  ROTATE_CMD = "exiftran -ai "
54
55
  COMPRESS_CMD = "jpegoptim --strip-all --max=90 "
55
56
  EXTERNAL_CMDS = [RESIZE_CMD, ROTATE_CMD, COMPRESS_CMD]
56
57
 
57
58
  WEBP_SEARCH = /(.+)\.webp/i
58
- WEBP_REPLACE = '\1.jpg'
59
+ WEBP_REPLACE = '\1.png'
59
60
 
60
61
  PNG_SEARCH = /(.+)\.png/i
61
62
  PNG_REPLACE = '\1.jpg'
62
63
  JPG_SEARCH = /(.+)\.jpe?g/i
64
+ HEIC_SEARCH = /(.+)\.heic/i
65
+ HEIC_REPLACE = '\1.jpg'
66
+
63
67
  EXCLUDE_PAT = /^_/ # 先頭が"_"の場合は除外
64
68
 
65
69
  def self.run(argv)
@@ -133,7 +137,7 @@ EOM
133
137
  filename.sub(OTHER_JPG_SEARCH, OTHER_JPG_REPLACE)
134
138
  end
135
139
 
136
- def self.replace_webp2jpg(filename)
140
+ def self.replace_webp2png(filename)
137
141
  filename.sub(WEBP_SEARCH, WEBP_REPLACE)
138
142
  end
139
143
 
@@ -141,6 +145,10 @@ EOM
141
145
  filename.sub(PNG_SEARCH, PNG_REPLACE)
142
146
  end
143
147
 
148
+ def self.replace_heic2jpg(filename)
149
+ filename.sub(HEIC_SEARCH, HEIC_REPLACE)
150
+ end
151
+
144
152
  def self.match_exclude_image?(filename)
145
153
  filename =~ EXCLUDE_PAT
146
154
  end
@@ -171,10 +179,10 @@ EOM
171
179
  if exclude_image?(filepath)
172
180
  return
173
181
  end
174
-
175
182
  filepath = rename_image(filepath)
176
- filepath = webp2jpg(filepath)
183
+ filepath = webp2png(filepath)
177
184
  filepath = png2jpg(filepath)
185
+ filepath = heic2jpg(filepath)
178
186
  filepath = resize_jpg(filepath)
179
187
  filepath = rotate_jpg(filepath)
180
188
  filepath = compress_jpg(filepath)
@@ -199,13 +207,16 @@ EOM
199
207
  dir = File.dirname(filepath)
200
208
  topath = File.join(dir, toname)
201
209
  puts "rename: #{filepath} => #{topath}"
202
- FileUtils.mv(filepath, topath) unless @opts[:n]
210
+ # FileUtils.mv(filepath, topath, :force => true) unless @opts[:n]
211
+ # aaa.JPG => aaa.jpgを成功させるためにFIleUtils.mv(same fileエラーがでる)ではなくmvを使う
212
+ cmd = "mv \"#{filepath}\" \"#{topath}\""
213
+ system(cmd)
203
214
  return topath
204
215
  end
205
216
 
206
- def webp2jpg(filepath)
217
+ def webp2png(filepath)
207
218
  fromname = File.basename(filepath)
208
- toname = self.class.replace_webp2jpg(fromname)
219
+ toname = self.class.replace_webp2png(fromname)
209
220
  return filepath if fromname == toname
210
221
 
211
222
  dir = File.dirname(filepath)
@@ -235,6 +246,23 @@ EOM
235
246
  return topath
236
247
  end
237
248
 
249
+ def heic2jpg(filepath)
250
+ fromname = File.basename(filepath)
251
+ toname = self.class.replace_heic2jpg(fromname)
252
+ # puts "heic2jpg #{fromname}=>#{toname}"
253
+ return filepath if fromname == toname
254
+
255
+ dir = File.dirname(filepath)
256
+ topath = File.join(dir, toname)
257
+ puts "convert: #{filepath} => #{topath}"
258
+ # convert ~/Desktop/test.heic -o ~/Desktop/test.jpg
259
+ cmd = "#{CONVERT_CMD} \"#{filepath}\" \"#{topath}\""
260
+ if system(cmd)
261
+ FileUtils.rm(filepath)
262
+ end
263
+ return topath
264
+ end
265
+
238
266
  def resize_jpg(filepath)
239
267
  fromname = File.basename(filepath)
240
268
  unless fromname =~ JPG_SEARCH
@@ -1,3 +1,3 @@
1
1
  module Imagetools
2
- VERSION = "1.1.0"
2
+ VERSION = "1.4.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.1.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - src
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.0.3
174
+ rubygems_version: 3.1.6
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Image Tools.