carrierwave-graphicsmagick 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/carrierwave-graphicsmagick.gemspec +23 -0
- data/lib/carrierwave-graphicsmagick.rb +2 -0
- data/lib/carrierwave/.DS_Store +0 -0
- data/lib/carrierwave/graphicsmagick.rb +204 -0
- data/lib/carrierwave/graphicsmagick/version.rb +5 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chad McGimpsey
|
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,29 @@
|
|
1
|
+
# Carrierwave::Graphicsmagick
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-graphicsmagick'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carrierwave-graphicsmagick
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave/graphicsmagick/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "carrierwave-graphicsmagick"
|
8
|
+
gem.version = CarrierWave::GraphicsMagick::VERSION
|
9
|
+
gem.authors = ["Chad McGimpsey"]
|
10
|
+
gem.email = ["chad.mcgimpsey@gmail.com"]
|
11
|
+
gem.description = "Convenience methods for using CarrierWave with the GraphicsMagick high performance CLI gem."
|
12
|
+
gem.summary = "Convenience methods for using CarrierWave with the GraphicsMagick high performance CLI gem."
|
13
|
+
gem.homepage = "https://github.com/dignoe/carrierwave-graphicsmagick"
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.add_dependency('graphicsmagick')
|
17
|
+
gem.add_dependency('carrierwave')
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,204 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
|
3
|
+
# Much of this is has been shamelessly taken from the CarrierWave::MiniMagick module
|
4
|
+
# https://github.com/carrierwaveuploader/carrierwave
|
5
|
+
|
6
|
+
module GraphicsMagick
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
begin
|
11
|
+
require "graphicsmagick"
|
12
|
+
rescue LoadError => e
|
13
|
+
e.message << " (You may need to install the graphicsmagick gem)"
|
14
|
+
raise e
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def convert(format)
|
20
|
+
process :convert => format
|
21
|
+
end
|
22
|
+
|
23
|
+
def auto_orient
|
24
|
+
process :auto_orient
|
25
|
+
end
|
26
|
+
|
27
|
+
def strip
|
28
|
+
process :strip
|
29
|
+
end
|
30
|
+
|
31
|
+
def resize_to_limit(width, height)
|
32
|
+
process :resize_to_limit => [width, height]
|
33
|
+
end
|
34
|
+
|
35
|
+
def resize_to_fit(width, height)
|
36
|
+
process :resize_to_fit => [width, height]
|
37
|
+
end
|
38
|
+
|
39
|
+
def resize_to_fill(width, height, gravity='Center')
|
40
|
+
process :resize_to_fill => [width, height, gravity]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Changes the image encoding format to the given format
|
46
|
+
#
|
47
|
+
# See http://www.graphicsmagick.org/mogrify.html
|
48
|
+
#
|
49
|
+
# === Parameters
|
50
|
+
#
|
51
|
+
# [format (#to_s)] an abreviation of the format
|
52
|
+
#
|
53
|
+
# === Yields
|
54
|
+
#
|
55
|
+
# [GraphicsMagick::Image] additional manipulations to perform
|
56
|
+
#
|
57
|
+
# === Examples
|
58
|
+
#
|
59
|
+
# image.convert(:png)
|
60
|
+
#
|
61
|
+
def convert(format)
|
62
|
+
manipulate! do |img|
|
63
|
+
img.format(format.to_s.downcase)
|
64
|
+
img = yield(img) if block_given?
|
65
|
+
img
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Auto rotates the file (useful for images taken with a digital camera)
|
71
|
+
#
|
72
|
+
def auto_orient
|
73
|
+
manipulate! do |img|
|
74
|
+
img.auto_orient
|
75
|
+
img = yield(img) if block_given?
|
76
|
+
img
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Remove all profiles and text attributes from the image
|
82
|
+
#
|
83
|
+
def strip
|
84
|
+
manipulate! do |img|
|
85
|
+
img.strip
|
86
|
+
img = yield(img) if block_given?
|
87
|
+
img
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Resize the image to fit within the specified dimensions while retaining
|
93
|
+
# the original aspect ratio. Will only resize the image if it is larger than the
|
94
|
+
# specified dimensions. The resulting image may be shorter or narrower than specified
|
95
|
+
# in the smaller dimension but will not be larger than the specified values.
|
96
|
+
#
|
97
|
+
# === Parameters
|
98
|
+
#
|
99
|
+
# [width (Integer)] the width to scale the image to
|
100
|
+
# [height (Integer)] the height to scale the image to
|
101
|
+
#
|
102
|
+
# === Yields
|
103
|
+
#
|
104
|
+
# [GraphicsMagick::Image] additional manipulations to perform
|
105
|
+
#
|
106
|
+
def resize_to_limit(width, height)
|
107
|
+
manipulate! do |img|
|
108
|
+
img.resize "#{width}x#{height}>"
|
109
|
+
img = yield(img) if block_given?
|
110
|
+
img
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# Resize the image to fit within the specified dimensions while retaining
|
116
|
+
# the original aspect ratio. The image may be shorter or narrower than
|
117
|
+
# specified in the smaller dimension but will not be larger than the specified values.
|
118
|
+
#
|
119
|
+
# === Parameters
|
120
|
+
#
|
121
|
+
# [width (Integer)] the width to scale the image to
|
122
|
+
# [height (Integer)] the height to scale the image to
|
123
|
+
#
|
124
|
+
# === Yields
|
125
|
+
#
|
126
|
+
# [GraphicsMagick::Image] additional manipulations to perform
|
127
|
+
#
|
128
|
+
def resize_to_fit(width, height)
|
129
|
+
manipulate! do |img|
|
130
|
+
img.resize "#{width}x#{height}"
|
131
|
+
img = yield(img) if block_given?
|
132
|
+
img
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Resize the image to fit within the specified dimensions while retaining
|
138
|
+
# the aspect ratio of the original image. If necessary, crop the image in the
|
139
|
+
# larger dimension.
|
140
|
+
#
|
141
|
+
# === Parameters
|
142
|
+
#
|
143
|
+
# [width (Integer)] the width to scale the image to
|
144
|
+
# [height (Integer)] the height to scale the image to
|
145
|
+
# [gravity (String)] the current gravity suggestion (default: 'Center'; options: 'NorthWest', 'North', 'NorthEast', 'West', 'Center', 'East', 'SouthWest', 'South', 'SouthEast')
|
146
|
+
#
|
147
|
+
# === Yields
|
148
|
+
#
|
149
|
+
# [GraphicsMagick::Image] additional manipulations to perform
|
150
|
+
#
|
151
|
+
def resize_to_fill(width, height, gravity = 'Center')
|
152
|
+
manipulate! do |img|
|
153
|
+
img.resize("#{width}x#{height}^")
|
154
|
+
.gravity(gravity)
|
155
|
+
.background("rgba(255,255,255,0.0)")
|
156
|
+
.extent("#{width}x#{height}")
|
157
|
+
img = yield(img) if block_given?
|
158
|
+
img
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Manipulate the image with GraphicsMagick. This method will pass the image
|
164
|
+
# to the supplied block. It will NOT save the image to disk by default. Override
|
165
|
+
# this by passing true as the only argument. Note: by default, the image is only
|
166
|
+
# saved after all processes have been run. If you are using this method to utilize
|
167
|
+
# Graphicsmagick utilities other than mogrify, then make sure all processes have
|
168
|
+
# been explicitly written to disk first, or call manipulate(true) before using
|
169
|
+
# built in convenience methods.
|
170
|
+
#
|
171
|
+
# === Gotcha
|
172
|
+
#
|
173
|
+
# This method assumes that the object responds to +current_path+.
|
174
|
+
# Any class that this module is mixed into must have a +current_path+ method.
|
175
|
+
# CarrierWave::Uploader does, so you won't need to worry about this in
|
176
|
+
# most cases.
|
177
|
+
#
|
178
|
+
#
|
179
|
+
# === Yields
|
180
|
+
#
|
181
|
+
# [GraphicsMagick::Image] manipulations to perform
|
182
|
+
#
|
183
|
+
#
|
184
|
+
def manipulate!(save_image = false)
|
185
|
+
cache_stored_file! if !cached?
|
186
|
+
@_gimage ||= ::GraphicsMagick::Image.new(current_path)
|
187
|
+
@_gimage = yield(@_gimage)
|
188
|
+
@_image.write(current_path) if save_image
|
189
|
+
@_gimage
|
190
|
+
rescue => e
|
191
|
+
raise CarrierWave::ProcessingError.new("Failed to manipulate file! #{e}")
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
def process!(*)
|
196
|
+
result = super
|
197
|
+
if @_gimage
|
198
|
+
@_gimage.write!
|
199
|
+
@_gimage = nil
|
200
|
+
end
|
201
|
+
result
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-graphicsmagick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chad McGimpsey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: graphicsmagick
|
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: carrierwave
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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
|
+
description: Convenience methods for using CarrierWave with the GraphicsMagick high
|
47
|
+
performance CLI gem.
|
48
|
+
email:
|
49
|
+
- chad.mcgimpsey@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- carrierwave-graphicsmagick.gemspec
|
60
|
+
- lib/carrierwave-graphicsmagick.rb
|
61
|
+
- lib/carrierwave/.DS_Store
|
62
|
+
- lib/carrierwave/graphicsmagick.rb
|
63
|
+
- lib/carrierwave/graphicsmagick/version.rb
|
64
|
+
homepage: https://github.com/dignoe/carrierwave-graphicsmagick
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.25
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Convenience methods for using CarrierWave with the GraphicsMagick high performance
|
89
|
+
CLI gem.
|
90
|
+
test_files: []
|