wformat 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wformat ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'wformat'
@@ -0,0 +1,10 @@
1
+ require 'wall_merger.rb'
2
+ require 'wall_scaler.rb'
3
+
4
+ class WallInterface
5
+ BUILDERS = {"merge" => WallMerger,
6
+ "scale" => WallScaler}
7
+ def run(command, arguments)
8
+ BUILDERS[command].new.send(command, *arguments)
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # wall_merger.rb
2
+ require 'RMagick'
3
+ require 'wall_operations'
4
+ include Magick
5
+
6
+ class WallMerger
7
+ include WallOperations
8
+
9
+ def merge(image_one, image_two, options = {})
10
+ width_one = options['width_one'] || 1920
11
+ width_two = options['width_two'] || 1920
12
+ height_one = options['height_one'] || 1200
13
+ height_two = options['height_two'] || 1200
14
+ title = options['title'] || "#{File.basename(image_one, ".jpg")} and #{File.basename(image_two, ".jpg")}.jpg"
15
+
16
+ # prepare image will retrieve the image and scale it
17
+ im_one = prepare_image(image_one, width_one, height_one)
18
+ im_two = prepare_image(image_two, width_two, height_two)
19
+ result = prepare_backdrop(width_one, height_one, width_two, height_two)
20
+
21
+ # place through will drop the image onto the target with shifting
22
+ place_through(0, 0, width_one, height_one, im_one, result)
23
+ place_through(width_one, 0, width_two, height_two, im_two, result)
24
+
25
+ save_image(result, title)
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require 'RMagick'
2
+ include Magick
3
+
4
+ module WallOperations
5
+ # Minimally scales image to fill width_bound and height_bound. Will not overflow bounds
6
+ def prepare_image(image_name, width_bound, height_bound)
7
+ im = ImageList.new(image_name)
8
+ scale_factor = get_scaled_size(im, width_bound, height_bound)
9
+ im.scale!(scale_factor)
10
+
11
+ im
12
+ end
13
+
14
+ # Returns a scale factor for the image with the given bounds
15
+ def get_scaled_size(image, width_bound, height_bound)
16
+ width_multiplier = 1.0 * width_bound / image.columns
17
+ height_multiplier = 1.0 * height_bound / image.rows
18
+
19
+ if image.rows * width_multiplier <= height_bound
20
+ width_multiplier
21
+ else
22
+ height_multiplier
23
+ end
24
+ end
25
+
26
+ def prepare_backdrop(width_one, height_one, width_two = 0, height_two = 0)
27
+ Image.new(width_one + width_two, [height_one, height_two].max) { self.background_color = 'black'}
28
+ end
29
+
30
+ # Places image on target, also applying rightward or downward shift to given coordinates based on bounds
31
+ def place_through(x, y, width_bound, height_bound, image, target)
32
+ new_x = (width_bound - image.columns) / 2 + x
33
+ new_y = (height_bound - image.rows) / 2 + y
34
+ place_onto(new_x, new_y, image, target)
35
+ end
36
+
37
+ # Places image on target where top left corner of image goes to x and y coordinates
38
+ def place_onto(x, y, image, target)
39
+ target.import_pixels(x, y, image.columns, image.rows, 'RGB', image.export_pixels)
40
+ end
41
+
42
+ def save_image(image, title)
43
+ image.write(title)
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ # wall_scaler.rb
2
+ require 'RMagick'
3
+ require 'wall_operations'
4
+ include Magick
5
+
6
+ class WallScaler
7
+ include WallOperations
8
+
9
+ def scale(image, options = {})
10
+ width = options['width'] || 1920
11
+ height = options['height'] || 1200
12
+
13
+ title = options['title'] || "#{File.basename(image, ".jpg")} scaled.jpg"
14
+
15
+ im = prepare_image(image, width, height)
16
+ result = prepare_backdrop(width, height)
17
+
18
+ place_through(0, 0, width, height, im, result)
19
+ save_image(result, title)
20
+ end
21
+ end
data/lib/wformat.rb ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'wall_interface'
4
+
5
+ opts_banner = ""
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do |opts|
9
+ opts.banner = "Usage: wformat command [options] arguments"
10
+ opts_banner = opts.banner
11
+
12
+ opts.on('-h', '--help', 'Display This Screen') do
13
+ puts "wformat is a command line utility to format images as computer wallpapers"
14
+ puts "commands:\n merge"
15
+ puts opts
16
+ exit
17
+ end
18
+
19
+ opts.on('--widthone=WIDTH', Integer, 'Left Monitor WIDTH') do |width|
20
+ options['width_one'] = width
21
+ end
22
+
23
+ opts.on('--widthtwo=WIDTH', Integer, 'Right Monitor WIDTH') do |width|
24
+ magic << self
25
+ options['width_two'] = width
26
+ end
27
+
28
+ opts.on('--heightone=HEIGHT', Integer, 'Left Monitor HEIGHT') do |height|
29
+ options['height_one'] = height
30
+ end
31
+
32
+ opts.on('--heighttwo=HEIGHT', Integer, 'Right Monitor HEIGHT') do |height|
33
+ options['height_two'] = height
34
+ end
35
+
36
+ opts.on('--width=WIDTH', Integer, 'Monitor Width') do |width|
37
+ options['width'] = width
38
+ end
39
+
40
+ opts.on('--height=HEIGHT', Integer, 'Monitor Height') do |height|
41
+ options['height'] = height
42
+ end
43
+
44
+ opts.on('--title=TITLE', "Output filename") do |title|
45
+ options['title'] = title
46
+ end
47
+
48
+ opts.on('--trace', "Provide stack trace when error occurs") do
49
+ options['trace'] = true
50
+ end
51
+ end
52
+
53
+ begin
54
+ optparse.parse!
55
+ help_message if ARGV.empty?
56
+
57
+ # parse command out from the arguments
58
+ command = ARGV.shift
59
+ arguments = ARGV << options
60
+
61
+ interface = WallInterface.new
62
+ interface.run(command, arguments)
63
+ rescue => ex
64
+ if options['trace']
65
+ puts "#{ex.inspect}"
66
+ else
67
+ puts "There was an error! Add the --trace switch for the stack trace"
68
+ end
69
+ puts opts_banner
70
+ exit
71
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wformat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Mah
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: &10502880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.13'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *10502880
25
+ description: ! "wformat is a command line utility to organize collections of wallpapers\n\n
26
+ \ For now, it can only reformat images into proper sizes(for dualmonitors too)\n\n
27
+ \ \n\n Soon it will feature organization through renaming and the ability to
28
+ search for duplicates of images"
29
+ email: mahhaha@gmail.com
30
+ executables:
31
+ - wformat
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/wformat.rb
36
+ - lib/wall_interface.rb
37
+ - lib/wall_operations.rb
38
+ - lib/wall_merger.rb
39
+ - lib/wall_scaler.rb
40
+ - bin/wformat
41
+ homepage: https://github.com/DavidMah/wformat
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.12
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: wformat is a command line utility to organize collections of wallpapers
65
+ test_files: []