image_stamping 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ae1af57d7afa48cdc42e1040a2b7af164960e56
4
+ data.tar.gz: 7f4612c94937ee66e40e3b254e98e72e4d6f8b61
5
+ SHA512:
6
+ metadata.gz: 9d45f8e16c016ab8e1b7688b9dd4acbaf0cbeeeb40bc86366e950f5dea7f08adac25d723f5efd04796c55fd0b063c192cb56918045731a002e8eda7465186011
7
+ data.tar.gz: 2b4ad0fcbec97c3b1d803238be3c8c8707806c73c1e42948ee4520166641fd229c02951913e37d75e7bbadad8053a6732784fa004f05876040432c761777da36
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in image_stamping.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jone Samra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # ImageStamping
2
+
3
+ An easy way to add text to an image using ImageMagic.
4
+
5
+ ## Installation
6
+
7
+ To use the gem you have to have the ImageMagick Installed in your system. On OSX i had to...
8
+
9
+ brew install imagemagick
10
+
11
+ When I worked on the code, I got An exception thrown telling me that the fonts were missing. So i had to download these from
12
+
13
+ [http://sourceforge.net/projects/gs-fonts/?source=dlp](http://sourceforge.net/projects/gs-fonts/?source=dlp)
14
+
15
+ and place them into
16
+
17
+ /usr/local/share/ghostscript/fonts
18
+
19
+
20
+ Once the above is done, you can now install the gem...
21
+
22
+ gem 'image_stamping'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install image_stamping
31
+
32
+ ## Usage
33
+
34
+ ```
35
+ require "image_stamping"`
36
+
37
+ #Create an instance
38
+ i = ImageStamping::ImageStamper.new
39
+
40
+ #We want to place the text in the north west corner
41
+ #The options here can be either :northwest, :northeast, :southwest and :southeast
42
+ i.gravity :northwest
43
+
44
+ #With the font size = 32
45
+ i.font_size = 32
46
+
47
+ #We want the color of the text to be yellow
48
+ i.font_color = "yellow"
49
+
50
+ #And font style would be italic
51
+ i.font_italic = true
52
+
53
+ #The input file to work on would be...
54
+ i.input_file = "image.jpg"
55
+
56
+ #The new file with the text would be called...
57
+ i.output_file = "image_stamped"
58
+
59
+ #Stamp the image with the text given as the first parameter
60
+ #The second parameter would be the width of the rectangle within which the text is positioned (default = 0)
61
+ #The third parameter would be the height of the rectangle within which the text is positioned (default = 0)
62
+ #The forth parameter would be the x offset of the rectangle (default = 30)
63
+ #And the fifth would be the y offset of the rectangle (default = 30)
64
+
65
+ i.stamp("JohnnyBoy")
66
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'image_stamping/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "image_stamping"
8
+ spec.version = ImageStamping::VERSION
9
+ spec.authors = ["Jone Samra"]
10
+ spec.email = ["jonemob@gmail.com"]
11
+ spec.summary = %q{An easy way to add text to an image using ImageMagic & the RMagick gem.}
12
+ spec.description = %q{An easy way to add text to an image using ImageMagic & the RMagick gem.}
13
+ spec.homepage = "https://github.com/phenomen2277/image_stamping"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rmagick", "~> 2.13.2"
24
+ end
@@ -0,0 +1,3 @@
1
+ module ImageStamping
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,64 @@
1
+ require "RMagick"
2
+ require "image_stamping/version"
3
+
4
+ module ImageStamping
5
+ class ImageStamper
6
+ attr_accessor :input_file, :output_file, :font, :font_size, :font_color, :font_bold, :font_italic
7
+
8
+ def initialize()
9
+ @input_file = ''
10
+ @output_file = ''
11
+
12
+ @font = 'Arial'
13
+ @font_size = 32
14
+ @font_color = 'white'
15
+ @font_bold = false
16
+ @font_italic = false
17
+ @gravity_value = Magick::SouthEastGravity
18
+ end
19
+
20
+ def stamp(text, width = 0, height = 0, x = 30, y = 30)
21
+ raise RuntimeError, "The input file does not exist" if @input_file.empty? || !file_exists?(@input_file)
22
+ raise RuntimeError, "The output file has not been given" if @output_file.empty?
23
+
24
+ begin
25
+ img = Magick::Image.read(@input_file).first
26
+ drawing = Magick::Draw.new
27
+ drawing.font = @font
28
+ drawing.pointsize = @font_size
29
+ drawing.font_weight = Magick::BoldWeight if @font_bold
30
+ drawing.font_style = Magick::ItalicStyle if @font_italic
31
+ drawing.fill = @font_color
32
+
33
+ drawing.gravity = @gravity_value
34
+ drawing.annotate(img, width, height, x, y, text)
35
+ img.write(@output_file)
36
+ rescue Exception => e
37
+ raise RuntimeError, e.message
38
+ end
39
+
40
+ true
41
+ end
42
+
43
+ def gravity(value)
44
+ case value
45
+ when :northeast
46
+ @gravity_value = Magick::NorthEastGravity
47
+ when :northwest
48
+ @gravity_value = Magick::NorthWestGravity
49
+ when :southeast
50
+ @gravity_value = Magick::SouthEastGravity
51
+ when :southwest
52
+ @gravity_value = Magick::SouthWestGravity
53
+ else
54
+ @gravity_value = Magick::SouthEastGravity
55
+ end
56
+ end
57
+
58
+ private
59
+ def file_exists?(file)
60
+ return true if (File.file?(file))
61
+ false
62
+ end
63
+ end
64
+ end
data/test/1.jpg ADDED
Binary file
@@ -0,0 +1,70 @@
1
+ require "test_helper"
2
+
3
+ class ImageStamperTest < Test::Unit::TestCase
4
+
5
+ def test_throw_exception_if_input_file_is_not_given
6
+ i = create_image_stamper
7
+ assert_raise RuntimeError do
8
+ i.stamp("JohnnyBoy")
9
+ end
10
+ end
11
+
12
+ def test_add_text_stamp_in_north_west
13
+ i = create_image_stamper
14
+ i.gravity :northwest
15
+ i.font_size = 32
16
+ i.font_color = "yellow"
17
+ i.font_italic = true
18
+ i.font_bold = true
19
+ i.input_file = current_dir + "/1.jpg"
20
+ i.output_file = current_dir + "/north_west_stamp.jpg"
21
+
22
+ assert i.stamp("Baghdad!")
23
+ end
24
+
25
+ def test_add_text_stamp_in_north_east
26
+ i = create_image_stamper
27
+ i.gravity :northeast
28
+ i.font_size = 32
29
+ i.font_color = "yellow"
30
+
31
+ i.input_file = current_dir + "/1.jpg"
32
+ i.output_file = current_dir + "/north_east_stamp.jpg"
33
+
34
+ assert i.stamp("Baghdad!")
35
+ end
36
+
37
+ def test_add_text_stamp_in_south_west
38
+ i = create_image_stamper
39
+ i.gravity :southwest
40
+ i.font_size = 32
41
+ i.font_color = "yellow"
42
+
43
+ i.input_file = current_dir + "/1.jpg"
44
+ i.output_file = current_dir + "/south_west_stamp.jpg"
45
+
46
+ assert i.stamp("Baghdad!")
47
+ end
48
+
49
+ def test_add_text_stamp_in_south_east
50
+ i = create_image_stamper
51
+ i.gravity :southeast
52
+ i.font_size = 32
53
+ i.font_color = "yellow"
54
+
55
+ i.input_file = current_dir + "/1.jpg"
56
+ i.output_file = current_dir + "/south_east_stamp.jpg"
57
+
58
+ assert i.stamp("Baghdad!")
59
+ end
60
+
61
+
62
+ private
63
+ def create_image_stamper
64
+ i = ImageStamping::ImageStamper.new
65
+ end
66
+
67
+ def current_dir
68
+ File.expand_path File.dirname(__FILE__)
69
+ end
70
+ end
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require "image_stamping"
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image_stamping
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jone Samra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rmagick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.13.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.13.2
55
+ description: An easy way to add text to an image using ImageMagic & the RMagick gem.
56
+ email:
57
+ - jonemob@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - image_stamping.gemspec
68
+ - lib/image_stamping.rb
69
+ - lib/image_stamping/version.rb
70
+ - test/1.jpg
71
+ - test/image_stamper_test.rb
72
+ - test/test_helper.rb
73
+ homepage: https://github.com/phenomen2277/image_stamping
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: An easy way to add text to an image using ImageMagic & the RMagick gem.
97
+ test_files:
98
+ - test/1.jpg
99
+ - test/image_stamper_test.rb
100
+ - test/test_helper.rb