watermark_paperclip_processor 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
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
+ # Specify your gem's dependencies in watermark_paperclip_processor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey
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,23 @@
1
+ watermark_paperclip_processor
2
+ =============================
3
+
4
+ Watermark processor for Paperclip gem
5
+
6
+ Usage:
7
+
8
+ Gemfile:
9
+
10
+ gem "watermark_paperclip_processor"
11
+
12
+ Model:
13
+
14
+ has_attached_file :data,
15
+ :processors => [:watermark],
16
+ :styles => {
17
+ :big => {
18
+ :geometry => "660x400>",
19
+ :watermark_path => "#{Rails.root}/public/images/watermark.png",
20
+ :position => "SouthEast"
21
+ },
22
+ :normal => "361x226#",
23
+ ...
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ module WatermarkPaperclipProcessor
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module WatermarkPaperclipProcessor
2
+ VERSION = "0.0.11"
3
+ end
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+ module Paperclip
3
+ class Watermark < Processor
4
+ attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :watermark_path, :overlay, :position
5
+
6
+ def initialize file, options = {}, attachment = nil
7
+ super
8
+ geometry = options[:geometry]
9
+ @file = file
10
+ @crop = geometry[-1,1] == '#'
11
+ @target_geometry = Geometry.parse geometry
12
+ @current_geometry = Geometry.from_file @file
13
+ @convert_options = options[:convert_options]
14
+ @whiny = options[:whiny].nil? ? true : options[:whiny]
15
+ @format = options[:format]
16
+ @watermark_path = options[:watermark_path]
17
+ @position = options[:position].nil? ? "SouthEast" : options[:position]
18
+ @overlay = options[:overlay].nil? ? true : false
19
+ @current_format = File.extname(@file.path)
20
+ @basename = File.basename(@file.path, @current_format)
21
+ end
22
+
23
+ # Returns true if the +target_geometry+ is meant to crop.
24
+ def crop?
25
+ @crop
26
+ end
27
+
28
+ # Returns true if the image is meant to make use of additional convert options.
29
+ def convert_options?
30
+ not @convert_options.blank?
31
+ end
32
+
33
+ # Performs the conversion of the +file+ into a watermark. Returns the Tempfile
34
+ # that contains the new image.
35
+ def make
36
+ dst = Tempfile.new([@basename, @format].compact.join("."))
37
+ dst.binmode
38
+ if watermark_path
39
+ command = "composite"
40
+ params = "-gravity #{@position} #{watermark_path} #{fromfile} #{transformation_command} #{tofile(dst)}"
41
+ else
42
+ command = "convert"
43
+ params = "#{fromfile} #{transformation_command} #{tofile(dst)}"
44
+ end
45
+ begin
46
+ success = Paperclip.run(command, params)
47
+ rescue PaperclipCommandLineError
48
+ raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
49
+ end
50
+ dst
51
+ end
52
+
53
+ def fromfile
54
+ "\"#{ File.expand_path(@file.path) }[0]\""
55
+ end
56
+
57
+ def tofile(destination)
58
+ "\"#{ File.expand_path(destination.path) }[0]\""
59
+ end
60
+
61
+ def transformation_command
62
+ scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
63
+ trans = "-resize \"#{scale}\""
64
+ trans << " -crop \"#{crop}\" +repage" if crop
65
+ trans << " #{convert_options}" if convert_options?
66
+ trans
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ require "watermark_paperclip_processor/engine"
2
+ require "watermark_paperclip_processor/watermark"
3
+ require "watermark_paperclip_processor/version"
4
+
5
+ module WatermarkPaperclipProcessor; end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'watermark_paperclip_processor/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "watermark_paperclip_processor"
8
+ gem.version = WatermarkPaperclipProcessor::VERSION
9
+ gem.authors = ["Andrey"]
10
+ gem.email = ["railscode@gmail.com"]
11
+ gem.description = "Watermark processor for Paperclip gem"
12
+ gem.summary = "Watermark processor for Paperclip gem"
13
+ gem.homepage = "https://github.com/vav/watermark_paperclip_processor"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "paperclip", ">= 3.1.0"
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watermark_paperclip_processor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-17 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: 3.1.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: 3.1.0
30
+ description: Watermark processor for Paperclip gem
31
+ email:
32
+ - railscode@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/watermark_paperclip_processor.rb
43
+ - lib/watermark_paperclip_processor/engine.rb
44
+ - lib/watermark_paperclip_processor/version.rb
45
+ - lib/watermark_paperclip_processor/watermark.rb
46
+ - watermark_paperclip_processor.gemspec
47
+ homepage: https://github.com/vav/watermark_paperclip_processor
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Watermark processor for Paperclip gem
71
+ test_files: []