carrierwave-matte 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
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
data/.rvmrc ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if ! rvm list | grep -q ruby-1.9.3-p194 ; then
4
+ rvm install 1.9.3-p194
5
+ fi
6
+
7
+ rvm 1.9.3-p194@ryantownsend_carrierwave_matte --create
8
+
9
+ if ! gem list | grep -q bundler ; then
10
+ gem install --no-ri --no-rdoc bundler
11
+ bundle install --without production
12
+ fi
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ryan Townsend
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.
@@ -0,0 +1,33 @@
1
+ # CarrierwaveMatte
2
+
3
+ Adds a 'matte' processor to Carrierwave, allowing you to specify a background colour for an image.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "carrierwave-matte"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install carrierwave-matte
18
+
19
+ ## Usage
20
+
21
+ Really simple, use any colour hex code you wish.
22
+
23
+ class YourUploader < CarrierWave::Uploader::Base
24
+ process matte: "#68a14f"
25
+ end
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/carrierwave_matte/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.authors = ["Ryan Townsend"]
6
+ s.email = ["ryan@ryantownsend.co.uk"]
7
+ s.description = "Adds a 'matte' processor to Carrierwave, allowing you to specify a background colour for an image."
8
+ s.summary = s.description
9
+ s.homepage = "https://github.com/ryantownsend/carrierwave-matte"
10
+
11
+ s.files = `git ls-files`.split($\)
12
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ s.test_files = s.files.grep(%r{^(spec|features)/})
14
+ s.name = "carrierwave-matte"
15
+ s.require_paths = ["lib"]
16
+ s.version = CarrierwaveMatte::VERSION
17
+
18
+ s.add_dependency "carrierwave"
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "mini_magick"
21
+ end
@@ -0,0 +1,4 @@
1
+ require "carrierwave_matte/version"
2
+ require "carrierwave_matte/processor"
3
+
4
+ module CarrierwaveMatte; end
@@ -0,0 +1,28 @@
1
+ require "carrierwave"
2
+
3
+ module CarrierwaveMatte
4
+ module Processor
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ base.send(:include, InstanceMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def matte(color)
12
+ process matte: color
13
+ end
14
+ end
15
+
16
+ module InstanceMethods
17
+ def matte(color)
18
+ manipulate! do |img|
19
+ img.background color, "-flatten", "+matte"
20
+ img = yield(img) if block_given?
21
+ img
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ CarrierWave::Uploader::Base.send(:include, CarrierwaveMatte::Processor)
@@ -0,0 +1,3 @@
1
+ module CarrierwaveMatte
2
+ VERSION = "0.0.1"
3
+ end
Binary file
Binary file
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+ require_relative "../lib/carrierwave_matte/processor"
3
+
4
+ class TestUploader < CarrierWave::Uploader::Base
5
+ include CarrierWave::MiniMagick
6
+
7
+ process matte: "#ffffff"
8
+ end
9
+
10
+ describe CarrierwaveMatte::Processor do
11
+ describe "processing images" do
12
+ subject do
13
+ TestUploader.new(model, :remote_file)
14
+ end
15
+
16
+ let(:model) { mock("model") }
17
+ let(:image_file) { nil }
18
+
19
+ before(:each) do
20
+ TestUploader.enable_processing = true
21
+ subject.store!(File.open(image_file))
22
+ end
23
+
24
+ after(:each) do
25
+ subject.remove!
26
+ TestUploader.enable_processing = false
27
+ end
28
+
29
+ context "given a semi-transparent image" do
30
+ let(:image_file) do
31
+ File.new(File.join(File.dirname(__FILE__), "data/transparent.png"))
32
+ end
33
+
34
+ it "should append a white background" do
35
+ subject.recreate_versions!
36
+ expect(subject).to have_pixel(1, 1, "#ffffff")
37
+ end
38
+ end
39
+
40
+ context "given an opaque image" do
41
+ let(:image_file) do
42
+ File.new(File.join(File.dirname(__FILE__), "data/opaque.png"))
43
+ end
44
+
45
+ before(:each) do
46
+ subject.recreate_versions!
47
+ end
48
+
49
+ it "should not append a white background" do
50
+ expect(subject).not_to have_pixel(1, 1, "#ffffff")
51
+ end
52
+
53
+ it "should maintain the black background" do
54
+ expect(subject).to have_pixel(1, 1, "#000000")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+
3
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
@@ -0,0 +1,5 @@
1
+ require "carrierwave"
2
+
3
+ RSpec.configure do |configuration|
4
+ include CarrierWave::Test::Matchers
5
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = :expect
4
+ end
5
+
6
+ config.color_enabled = true
7
+ config.order = :random
8
+ end
@@ -0,0 +1,38 @@
1
+ module CarrierWave
2
+ module Test
3
+ module Matchers
4
+ class HavePixel
5
+ def initialize(x, y, color)
6
+ @x, @y, @color = x, y, color
7
+ end
8
+
9
+ def matches?(actual)
10
+ @actual = actual
11
+ # Satisfy expectation here. Return false or raise an error if it's not met.
12
+ image = ImageLoader.load_image(@actual.current_path).image
13
+ @actual_color = case image.run_command("convert", "#{@actual.current_path}[1x1+#{@x}+#{@y}]", "-depth 8", "txt:").split("\n")[1]
14
+ when /^0,0:.*(#[\da-fA-F]{6}).*$/ then $1
15
+ else nil
16
+ end
17
+ @color.downcase == @actual_color.downcase
18
+ end
19
+
20
+ def failure_message
21
+ "expected #{@actual.current_path.inspect} to have a #{@color} colored pixel at #{@x}, #{@y}, not #{@actual_color}."
22
+ end
23
+
24
+ def negative_failure_message
25
+ "expected #{@actual.current_path.inspect} not to have a #{@color} colored pixel at #{@x}, #{@y}."
26
+ end
27
+
28
+ def description
29
+ "have an #{@color} colored pixel at #{@x}, #{@y}."
30
+ end
31
+ end
32
+
33
+ def have_pixel(x, y, color)
34
+ HavePixel.new(x, y, color)
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-matte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Townsend
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: carrierwave
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mini_magick
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Adds a 'matte' processor to Carrierwave, allowing you to specify a background
63
+ colour for an image.
64
+ email:
65
+ - ryan@ryantownsend.co.uk
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rvmrc
72
+ - Gemfile
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - carrierwave_matte.gemspec
77
+ - lib/carrierwave_matte.rb
78
+ - lib/carrierwave_matte/processor.rb
79
+ - lib/carrierwave_matte/version.rb
80
+ - spec/data/opaque.png
81
+ - spec/data/transparent.png
82
+ - spec/processor_spec.rb
83
+ - spec/spec_helper.rb
84
+ - spec/support/carrierwave.rb
85
+ - spec/support/env.rb
86
+ - spec/support/matchers/carrierwave.rb
87
+ homepage: https://github.com/ryantownsend/carrierwave-matte
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Adds a 'matte' processor to Carrierwave, allowing you to specify a background
111
+ colour for an image.
112
+ test_files:
113
+ - spec/data/opaque.png
114
+ - spec/data/transparent.png
115
+ - spec/processor_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/carrierwave.rb
118
+ - spec/support/env.rb
119
+ - spec/support/matchers/carrierwave.rb