magick_round_corners 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTVlMzY3MTkwZGU2YTIyNTcyYjgyODdlYTk2MGY1YjRlNGViZWM2Mw==
5
+ data.tar.gz: !binary |-
6
+ OGQzYjg4ODhhY2I5Mzk2YTUxOGVhYTAxNzYwYTE3MzFhYmI3ZTIyNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ODExNTU3ODE3NTM4NWM1YWM4NTc3NjZlZjgwMDMwNThlMjNhYWQ2ZDFjMDdi
10
+ ZjdjNWQwYjY5Y2FiNWYyN2I4NjBmOWM2YWQ1YTk4OGZiODQwMGJmYzY3ZDVk
11
+ YzQ1YTI1Mjc3NWU0ZTRhZTlkMzE1OGZiNDdmYTYyMTUwNjFlZDk=
12
+ data.tar.gz: !binary |-
13
+ ZTE1MjVlYjFlZTUyNDQ4MjUxYmVmOWE5NzBhM2NiNTYzNDA4NzgyMzMxMjZh
14
+ NjQxMDc1MGNhOWVkYzg1MjE0MGI3NDMwZWIyYjlhZmIzMjVlMDU0ZmI4NWFi
15
+ Mjg0MjlkZDA5NWVkODVjYTk0YjkxMzZhMTYzMTgwMzJkMDVkZTM=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ magick_round_corners (1.0)
5
+ rmagick
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ rmagick (2.13.2)
12
+ rspec (2.13.0)
13
+ rspec-core (~> 2.13.0)
14
+ rspec-expectations (~> 2.13.0)
15
+ rspec-mocks (~> 2.13.0)
16
+ rspec-core (2.13.1)
17
+ rspec-expectations (2.13.0)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.13.1)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler
26
+ magick_round_corners!
27
+ rspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Magick Round Corners
2
+
3
+ This is a simple ruby gem that adds the instance method `round_corners`
4
+ transformation to `Magick::Image` class.
5
+
6
+
7
+ ## Installation
8
+
9
+ gem install magick_round_corners
10
+
11
+ or you can also can add it to you Gemfile
12
+
13
+ gem 'magick_round_corners'
14
+
15
+ ## Using it
16
+
17
+ Given an instance of `Magick::Image`, `image`, you can call `image.round_corners(RADIUS)`
18
+ where `RADIUS` is the desire radius to round the corners.
19
+
20
+ Yes, it is just like that!, Easy? No?
21
+
22
+ ## Dependency
23
+
24
+ * `rmagick`
25
+
26
+ ## Example
27
+
28
+ This example use
29
+
30
+ ![Original](sample.png)
31
+
32
+ To generate
33
+
34
+ ![Output](output.png)
35
+
36
+ :001 > require 'rmagick'
37
+ => true
38
+ :002 > require 'magick_round_corners'
39
+ => true
40
+ :003 > image = Magick::Image.read('sample.png').first
41
+ => sample.png PNG 300x300 300x300+0+0 DirectClass 8-bit 976b
42
+ :004 > rounded_corners_image = image.round_corners(50)
43
+ => sample.png PNG 300x300 300x300+0+0 DirectClass 8-bit
44
+ :005 > rounded_corners_image.write('output.png')
45
+ => sample.png=>output.png PNG 300x300 300x300+0+0 DirectClass 8-bit
46
+
47
+ # Frienly reminder
48
+
49
+ When saving/writing out your rounded images, **use** an extension that supports **transparencies** (a.k.a this will not generate rounded jpg images)
@@ -0,0 +1,19 @@
1
+ module MagickRoundCorners
2
+ module Transformation
3
+ class ::Magick::Image
4
+ def round_corners(radius = 8)
5
+ # Set a transparent background: pixels that are transparent will be
6
+ # discarded from the source image.
7
+ mask = ::Magick::Image.new(columns, rows) {self.background_color = 'transparent'}
8
+
9
+ # Create a white rectangle with rounded corners. This will become the
10
+ # mask for the area you want to retain in the original image.
11
+ ::Magick::Draw.new.stroke('none').stroke_width(0).fill('white').
12
+ roundrectangle(0, 0, columns, rows, radius, radius).
13
+ draw(mask)
14
+ # Apply the mask and write it out
15
+ composite(mask, ::Magick::CenterGravity, ::Magick::CopyOpacityCompositeOp)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module MagickRoundCorners
2
+ VERSION = 1.0
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'rmagick'
2
+ require 'magick_round_corners/transformation'
@@ -0,0 +1,25 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "magick_round_corners/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "magick_round_corners"
6
+ s.version = MagickRoundCorners::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Sebastian Arcila Valenzuela"]
9
+ s.email = ["sebastian@authy.com"]
10
+ s.homepage = "https://github.com/sarcilav/magick_round_corners"
11
+ s.summary = %q{A simple Ruby interface with ImageMagick to transform Images and add round corners.}
12
+ s.description = %q{A Ruby gem to easily transform images adding round corners.}
13
+ s.license = "MIT"
14
+
15
+ s.add_runtime_dependency 'rmagick'
16
+
17
+ s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'bundler'
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
25
+
data/output.png ADDED
Binary file
data/sample.png ADDED
Binary file
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "MagickRoundCorners::Transformation" do
4
+ it "should add round corners method to an instance of Magick::Image" do
5
+ ::Magick::Image.new.should respond_to(:round_corners)
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "MagickRoundCorners::Transformation" do
4
+ it "should add round corners method to an instance of Magick::Image" do
5
+ ::Magick::Image.new(1,1).should respond_to(:round_corners)
6
+ end
7
+
8
+ describe "Behavior" do
9
+ before do
10
+ @img = ::Magick::Image.new(10, 20)
11
+ end
12
+
13
+ it "should interface with a mask" do
14
+ dummy_mask = double()
15
+ ::Magick::Image.should_receive(:new).with(10, 20).and_return(dummy_mask)
16
+ ::Magick::Draw.stub_chain(:new, :stroke, :stroke_width, :fill, :roundrectangle, :draw)
17
+ @img.should_receive(:composite).with(dummy_mask, ::Magick::CenterGravity, ::Magick::CopyOpacityCompositeOp).and_return(@img)
18
+ @img.round_corners
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'magick_round_corners'
5
+
6
+
7
+ require 'rubygems'
8
+ require 'bundler'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magick_round_corners
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Arcila Valenzuela
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A Ruby gem to easily transform images adding round corners.
56
+ email:
57
+ - sebastian@authy.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - lib/magick_round_corners.rb
67
+ - lib/magick_round_corners/transformation.rb
68
+ - lib/magick_round_corners/version.rb
69
+ - magick_round_corners.gemspec
70
+ - output.png
71
+ - sample.png
72
+ - spec/magick_round_corners/transformation.rb
73
+ - spec/magick_round_corners/transformation_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/sarcilav/magick_round_corners
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A simple Ruby interface with ImageMagick to transform Images and add round
99
+ corners.
100
+ test_files:
101
+ - spec/magick_round_corners/transformation.rb
102
+ - spec/magick_round_corners/transformation_spec.rb
103
+ - spec/spec_helper.rb
104
+ has_rdoc: