imagetools 0.3.0 → 0.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 +4 -4
- data/Gemfile.lock +1 -1
- data/exe/iconextractor +6 -0
- data/exe/imageresizer +7 -0
- data/lib/imagetools/iconextractor.rb +87 -0
- data/lib/imagetools/imageresizer.rb +81 -0
- data/lib/imagetools/version.rb +1 -1
- data/test_iconextractor.sh +2 -0
- data/test_imageresizer.sh +2 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7217c6d917f940f4d9e9e5b1a3cfe37544dad01f3a6b5896de421da42da063bd
|
4
|
+
data.tar.gz: 780d16d4e031222447f655f65b1fccf3b6cc7a47fe2f4f52e5c9deab982a8347
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8166fedb954f8ad155f8f5128f4a56e79253dbdeac2afc63e482f2fe4dd26bfd6ce3ff54c387e4cf13cd334b22cf553029814fde67dfe00f3104659f0a754e10
|
7
|
+
data.tar.gz: e4214910ede9c5de20752fb95089f36e85a745e8f3d20ef6af3dac1cadeb83d45d18a1d100c19cd8936331fcb002dfe716eff8a13ccc65d159add8d4165d71ab
|
data/Gemfile.lock
CHANGED
data/exe/iconextractor
ADDED
data/exe/imageresizer
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "imagetools/version"
|
4
|
+
require "optparse"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
|
8
|
+
module Imagetools
|
9
|
+
class Iconextractor
|
10
|
+
def self.run(argv)
|
11
|
+
opts = {}
|
12
|
+
opt = OptionParser.new(argv)
|
13
|
+
opt.banner = "Usage: #{opt.program_name} [-h|--help] <app1 app2 app3 ...>"
|
14
|
+
opt.version = VERSION
|
15
|
+
opt.separator('')
|
16
|
+
opt.separator("Options:")
|
17
|
+
opt.on_head('-h', '--help', 'Show this message') do |v|
|
18
|
+
puts opt.help
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
|
22
|
+
opt.on('-o OUTDIR', '--output=OUTDIR', 'Output dir') {|v| opts[:o] = v}
|
23
|
+
opt.parse!(argv)
|
24
|
+
|
25
|
+
app_files = get_app_files(argv)
|
26
|
+
if app_files.size < 1
|
27
|
+
puts opt.help
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
command = Iconextractor.new(opts)
|
31
|
+
command.run(app_files)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_app_files(argv)
|
35
|
+
app_files = []
|
36
|
+
argv.each do |arg|
|
37
|
+
if FileTest.directory?(arg) && arg =~ /\.app/
|
38
|
+
app_path = File.expand_path(arg)
|
39
|
+
# puts app_path
|
40
|
+
app_files << app_path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
app_files
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(opts)
|
47
|
+
@opts = opts
|
48
|
+
end
|
49
|
+
|
50
|
+
def run(app_files)
|
51
|
+
app_files.each do |app_path|
|
52
|
+
icns_path = get_icns_path(app_path)
|
53
|
+
icns_to_png(icns_path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def get_icns_path(app_path)
|
59
|
+
info_plist = File.join(app_path, 'Contents/Info.plist')
|
60
|
+
# puts info_plist
|
61
|
+
json_str = `plutil -convert json #{info_plist} -o - `
|
62
|
+
json_data = JSON.parse(json_str)
|
63
|
+
icns_base = json_data["CFBundleIconFile"]
|
64
|
+
|
65
|
+
icns_path = File.join(app_path, "Contents/Resources/#{icns_base}.icns")
|
66
|
+
icns_path
|
67
|
+
|
68
|
+
# str = File.read(info_plist)
|
69
|
+
# data = JSON.parse(str)
|
70
|
+
# p data["CFBundleTypeIconFile"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def icns_to_png(icns_path)
|
74
|
+
outdir = @opts[:o] || '.'
|
75
|
+
|
76
|
+
icns_base = File.basename(icns_path)
|
77
|
+
png_base = icns_base.sub(/\.icns$/, '.png')
|
78
|
+
png_path = File.join(outdir, png_base)
|
79
|
+
|
80
|
+
cmd = "sips -s format png #{icns_path} --out #{png_path}"
|
81
|
+
puts cmd
|
82
|
+
if !system(cmd)
|
83
|
+
raise RuntimeError
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'imagetools/version'
|
4
|
+
require 'optparse'
|
5
|
+
require 'rmagick'
|
6
|
+
|
7
|
+
module Imagetools
|
8
|
+
class Imageresizer
|
9
|
+
def self.run(argv)
|
10
|
+
STDOUT.sync = true
|
11
|
+
opts = {}
|
12
|
+
opt = OptionParser.new(argv)
|
13
|
+
opt.banner = "Usage: #{opt.program_name} [-h|--help] <args>"
|
14
|
+
opt.version = VERSION
|
15
|
+
opt.separator('')
|
16
|
+
opt.separator("Options:")
|
17
|
+
opt.on_head('-h', '--help', 'Show this message') do |v|
|
18
|
+
puts opt.help
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
|
22
|
+
opt.on('--dry-run', 'Message only') {|v| opts[:dry_run] = v}
|
23
|
+
opt.on('-o OUTNAME', '--output=OUTNAME', 'Output file') {|v| opts[:o] = v}
|
24
|
+
opt.parse!(argv)
|
25
|
+
image_files = get_image_files(argv)
|
26
|
+
if image_files.size < 1
|
27
|
+
puts opt.help
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
command = Imageresizer.new(opts)
|
31
|
+
command.run(image_files[0])
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_image_files(argv)
|
35
|
+
image_files = []
|
36
|
+
argv.each do |arg|
|
37
|
+
arg = File.expand_path(arg)
|
38
|
+
if FileTest.file?(arg) && (arg =~ /\.jpe?g$/i || arg =~ /\.png/i)
|
39
|
+
image_files << arg
|
40
|
+
end
|
41
|
+
end
|
42
|
+
image_files
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(opts)
|
46
|
+
@opts = opts
|
47
|
+
end
|
48
|
+
|
49
|
+
def run(image_file)
|
50
|
+
imgdata = File.binread(image_file)
|
51
|
+
resultdata = center_and_pad(imgdata, 960, 640, 'white', ::Magick::CenterGravity)
|
52
|
+
|
53
|
+
outpath = @opts[:o] || 'image.png'
|
54
|
+
puts "write to #{outpath}"
|
55
|
+
File.binwrite("image.png", resultdata)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def center_and_pad(imgdata, width, height, background=:transparent, gravity=::Magick::CenterGravity)
|
60
|
+
img = Magick::Image.from_blob(imgdata).first
|
61
|
+
|
62
|
+
img = img.resize_to_fit(600, 600)
|
63
|
+
|
64
|
+
new_img = ::Magick::Image.new(width, height)
|
65
|
+
if background == :transparent
|
66
|
+
filled = new_img.matte_floodfill(1, 1)
|
67
|
+
else
|
68
|
+
filled = new_img.color_floodfill(1, 1, ::Magick::Pixel.from_color(background))
|
69
|
+
end
|
70
|
+
filled.composite!(img, gravity, ::Magick::OverCompositeOp)
|
71
|
+
# destroy_image(img)
|
72
|
+
# filled = yield(filled) if block_given?
|
73
|
+
# filled
|
74
|
+
# filled.write new_img_path
|
75
|
+
filled.format = "png"
|
76
|
+
filled.to_blob
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
pp
|
81
|
+
|
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.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: 2018-04-
|
11
|
+
date: 2018-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -71,8 +71,10 @@ email:
|
|
71
71
|
- src@srcw.net
|
72
72
|
executables:
|
73
73
|
- iconcreator
|
74
|
+
- iconextractor
|
74
75
|
- imageconcat
|
75
76
|
- imagefilter
|
77
|
+
- imageresizer
|
76
78
|
- imagetools
|
77
79
|
extensions: []
|
78
80
|
extra_rdoc_files: []
|
@@ -90,15 +92,19 @@ files:
|
|
90
92
|
- bin/setup
|
91
93
|
- build.sh
|
92
94
|
- exe/iconcreator
|
95
|
+
- exe/iconextractor
|
93
96
|
- exe/imageconcat
|
94
97
|
- exe/imagefilter
|
98
|
+
- exe/imageresizer
|
95
99
|
- exe/imagetools
|
96
100
|
- hazel_imagefilter_template.sh
|
97
101
|
- imagetools.gemspec
|
98
102
|
- lib/imagetools.rb
|
99
103
|
- lib/imagetools/iconcreator.rb
|
104
|
+
- lib/imagetools/iconextractor.rb
|
100
105
|
- lib/imagetools/imageconcat.rb
|
101
106
|
- lib/imagetools/imagefilter.rb
|
107
|
+
- lib/imagetools/imageresizer.rb
|
102
108
|
- lib/imagetools/version.rb
|
103
109
|
- sample/demo/.gitignore
|
104
110
|
- sample/demo/demo.xcodeproj/project.pbxproj
|
@@ -129,8 +135,10 @@ files:
|
|
129
135
|
- sample_iconcreator.sh
|
130
136
|
- test.sh
|
131
137
|
- test_iconcreator.sh
|
138
|
+
- test_iconextractor.sh
|
132
139
|
- test_imageconcat.sh
|
133
140
|
- test_imagefilter.sh
|
141
|
+
- test_imageresizer.sh
|
134
142
|
homepage: ''
|
135
143
|
licenses:
|
136
144
|
- MIT
|