paperclip-gmagick 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ require 'paperclip'
2
+ require 'tempfile'
3
+ require "paperclip_processors/gmagick"
4
+
@@ -0,0 +1,79 @@
1
+ module Paperclip
2
+ class GMagick
3
+
4
+ attr_accessor :source_file_options, :convert_options
5
+
6
+ def initialize(file, options = {}, attachment = nil)
7
+ @geometry = options[:geometry]
8
+ @file = file
9
+ @format = options[:format]
10
+ @current_format = File.extname(@file.path)
11
+ @basename = File.basename(@file.path, @current_format)
12
+
13
+ @target_geometry = (options[:string_geometry_parser] || Geometry).parse(@geometry)
14
+ @current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
15
+ end
16
+
17
+ def self.make(file, options = {}, attachment = nil)
18
+ new(file, options, attachment).make
19
+ end
20
+
21
+ def make
22
+ src = @file
23
+ dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
24
+
25
+ begin
26
+ parameters = []
27
+ parameters << source_file_options
28
+ parameters << ":source"
29
+ parameters << transformation_command
30
+ parameters << convert_options
31
+ parameters << ":dest"
32
+
33
+ parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
34
+
35
+ success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]'}", :dest => File.expand_path(dst.path))
36
+ rescue Cocaine::ExitStatusError => e
37
+ raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
38
+ rescue Cocaine::CommandNotFoundError => e
39
+ raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `gm convert` command. Please install GraphicsMagick.")
40
+ end
41
+
42
+ dst
43
+ end
44
+
45
+ def convert(arguments = "", local_options = {})
46
+ Paperclip.run('gm convert', arguments, local_options)
47
+ end
48
+
49
+ def identify(arguments = "", local_options = {})
50
+ Paperclip.run('gm identify', arguments, local_options)
51
+ end
52
+
53
+ # Returns the command ImageMagick's +convert+ needs to transform the image
54
+ # into the thumbnail.
55
+ def transformation_command
56
+ scale = transformation_to(@geometry)
57
+ trans = []
58
+ #trans << "-auto-orient" if auto_orient
59
+ trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty?
60
+ #trans << "-crop" << %["#{crop}"] << "+repage" if crop
61
+ trans
62
+ end
63
+
64
+ def crop?
65
+ @crop
66
+ end
67
+
68
+ def transformation_to(geometry)
69
+ geometry.gsub("#","")
70
+ end
71
+
72
+ # Returns true if the image is meant to make use of additional convert options.
73
+ def convert_options?
74
+ !@convert_options.nil? && !@convert_options.empty?
75
+ end
76
+
77
+ end
78
+
79
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-gmagick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Mulder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paperclip
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
+ description: Call GMagick instead of ImageMagick
31
+ email: mulder.patrick@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/paperclip-gmagick.rb
37
+ - lib/paperclip_processors/gmagick.rb
38
+ homepage: http://rubygems.org/gems/paperclip-gmagick
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.23
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Paperclip Processor for GMagick
62
+ test_files: []
63
+ has_rdoc: