profound 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
- require './lib/profound'
2
+ require 'pry'
3
+ require 'optparse'
4
+ require File.expand_path('../../lib/profound', __FILE__)
3
5
 
4
- Choice.options do
5
- banner 'Usage: profound [options] source "Caption or label" destination'
6
- header ''
7
- header 'Specific options:'
8
6
 
9
- option :theme do
10
- long '--theme=THEME'
11
- desc 'Theme to use (light, dark)'
12
- cast Symbol
13
- valid [:light, :dark]
14
- default :light
7
+ options = {
8
+ :theme => :dark
9
+ }
10
+ source, caption, destination = OptionParser.new do |opts|
11
+ opts.banner = 'Usage: profound [options] source "Caption or label" destination'
12
+ opts.separator ""
13
+ opts.separator "Specific options:"
14
+
15
+ opts.on("--theme=THEME", "light,dark") do |theme|
16
+ options[:theme] = theme.to_sym
15
17
  end
16
- end
18
+
19
+ opts.on("--filter=FILTER", "toycamera") do |filter|
20
+ options[:filter] = filter.to_sym
21
+ end
22
+
23
+ end.parse!
17
24
 
18
25
  unless ARGV.length == 3
19
26
  puts Choice.help
20
27
  exit(1)
21
28
  end
22
29
 
23
- Profound::Image.new(ARGV[0], ARGV[1], Choice.choices, ARGV[2]).convert
30
+ Profound::Image.new(source, caption, options, destination).convert
@@ -1,5 +1,5 @@
1
- require "profound/version"
2
- require 'choice'
1
+ require 'profound/version'
2
+ require 'profound/filters/toy_camera'
3
3
  require 'rmagick'
4
4
 
5
5
  module Profound
@@ -18,10 +18,10 @@ module Profound
18
18
  end
19
19
 
20
20
  class Image
21
+ include Profound::Filters::ToyCamera
22
+
21
23
  def initialize(source, caption, options, destination)
22
- @image_list = Magick::ImageList.new(source)
23
- @source = @image_list.first
24
- # @image_list = Magick::ImageList.new
24
+ @source = Magick::ImageList.new(source).first
25
25
  @target = Magick::ImageList.new
26
26
  @destination = destination
27
27
  @caption = caption
@@ -30,22 +30,40 @@ module Profound
30
30
  end
31
31
 
32
32
  def convert
33
- shadow!
34
- text!
35
- save!
33
+ shadow
34
+ text
35
+ filters
36
+ save
37
+ end
38
+
39
+ def text
40
+ @source = @source.composite(_text, Magick::CenterGravity, Magick::OverCompositeOp)
36
41
  end
37
42
 
38
- def text!
39
- @source = @source.composite(text, Magick::CenterGravity, Magick::OverCompositeOp)
43
+ def filters
44
+ case @options[:filter]
45
+ when :toycamera
46
+ toy_camera
47
+ end
40
48
  end
41
49
 
42
- def text(color = nil, stroke_width = 0)
50
+ def shadow
51
+ image = _text(40)
52
+ shadow = image.shadow(0, 0, 30).colorize(1, 1, 1, 0, @theme.inverse_color)
53
+ @source = @source.composite(shadow, Magick::CenterGravity, 20, 0, Magick::OverCompositeOp)
54
+ end
55
+
56
+ def save
57
+ @source.write(@destination)
58
+ end
59
+
60
+ def _text(stroke_width = 0)
43
61
  image = Magick::Image.new(@source.columns, 100) {
44
62
  self.background_color = 'none'
45
63
  }
46
64
  text = Magick::Draw.new
47
65
 
48
- color ||= @theme.color
66
+ color = @theme.color
49
67
  text.annotate(image, 0, 0, 0, 0, @caption) {
50
68
  self.fill = color
51
69
  self.font_family = 'Arial'
@@ -57,15 +75,5 @@ module Profound
57
75
 
58
76
  image
59
77
  end
60
-
61
- def shadow!
62
- image = text(@theme.inverse_color, 40)
63
- @source = @source.composite(image.shadow(0, 0, 30), Magick::CenterGravity, 20, 0, Magick::OverCompositeOp)
64
- end
65
-
66
- def save!
67
- # img = @image_list.flatten_images
68
- @source.write(@destination)
69
- end
70
78
  end
71
79
  end
@@ -0,0 +1,7 @@
1
+ module Profound::Filters
2
+ module ToyCamera
3
+ def toy_camera
4
+ @source = @source.modulate(1.2, 1.2)
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Profound
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "choice", "~> 0.1.6"
22
21
  spec.add_dependency "rmagick", "~> 2.13"
23
22
 
24
23
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,6 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: choice
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.1.6
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.1.6
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: rmagick
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +91,7 @@ files:
107
91
  - Rakefile
108
92
  - bin/profound
109
93
  - lib/profound.rb
94
+ - lib/profound/filters/toy_camera.rb
110
95
  - lib/profound/version.rb
111
96
  - profound.gemspec
112
97
  homepage: ''