imagetools 0.3.0 → 0.4.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: a471bcc97395de84d2626bd0708fe1463c3c0129056ffd99e62c2feaf4d81948
4
- data.tar.gz: 213abe065b40268e623affea31a2f0b390e3686e237f72b0644a2242741d448c
3
+ metadata.gz: 7217c6d917f940f4d9e9e5b1a3cfe37544dad01f3a6b5896de421da42da063bd
4
+ data.tar.gz: 780d16d4e031222447f655f65b1fccf3b6cc7a47fe2f4f52e5c9deab982a8347
5
5
  SHA512:
6
- metadata.gz: 71ed87582356c0b42bd24533b07c18624d23fcfda5fe5179710dda0dbc426b845590bef2256c6dde7dd2c7522f25976b75b6c6e6000be1d6d43329f3ed0c7f8a
7
- data.tar.gz: e7dcb59dcc670bfdd5bc54d82002ede1de839f4ba8039870a0f698b72e7cc7cc83a73f45020c90fd898f29dbfaaf5ae513cb726307219858990f0e6a291df365
6
+ metadata.gz: 8166fedb954f8ad155f8f5128f4a56e79253dbdeac2afc63e482f2fe4dd26bfd6ce3ff54c387e4cf13cd334b22cf553029814fde67dfe00f3104659f0a754e10
7
+ data.tar.gz: e4214910ede9c5de20752fb95089f36e85a745e8f3d20ef6af3dac1cadeb83d45d18a1d100c19cd8936331fcb002dfe716eff8a13ccc65d159add8d4165d71ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imagetools (0.3.0)
4
+ imagetools (0.4.0)
5
5
  rmagick
6
6
 
7
7
  GEM
data/exe/iconextractor ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'imagetools/iconextractor'
4
+
5
+ Imagetools::Iconextractor.run(ARGV)
6
+
data/exe/imageresizer ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'imagetools/imageresizer'
4
+
5
+ Imagetools::Imageresizer.run(ARGV)
6
+
7
+
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module Imagetools
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/iconextractor "$@"
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/imageresizer "$@"
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.3.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-20 00:00:00.000000000 Z
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