ack-paperclip-watermark 0.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: facf98547793a3c304ad2ca55a4a9f2e93341d12
4
+ data.tar.gz: 3a5408eadf577001e3bc0979ee1dcd8b941a4ae3
5
+ SHA512:
6
+ metadata.gz: 2cee4a8737ebd33c036d0e131d6061fa2e769586dd6e8312efc8750853936a856e6a2c734888af094bfabedd3d2009d12d7fbae4fe136553573d0db4049f15a4
7
+ data.tar.gz: 15b4243ad4270795b67bae167d079ff8770d9ff2feaa1966dea35e9aac6920f9d2a0b389ccf85715ac717b3a03b80b4fb0ff4c0d61aa94df1bdc46c5a9273a12
@@ -0,0 +1,18 @@
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
18
+ .idea/
@@ -0,0 +1 @@
1
+ paperclip-watermark
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-watermark.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Alexander Kiseliev
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,52 @@
1
+ # AckPaperclipWatermark
2
+
3
+ Fork of [PaperclipWatermark](https://github.com/vikewoods/paperclip-watermark)
4
+ Paperclip Watermark processor
5
+
6
+ ## Usage
7
+
8
+ Edit your paperclip model:
9
+
10
+ ```ruby
11
+ # app/models/assets.rb
12
+
13
+ class Asset < ActiveRecord::Base
14
+ attr_accessible :attachment
15
+
16
+ # Paperclip image attachments
17
+ has_attached_file :attachment, :processors => [:watermark],
18
+ :styles => {
19
+ :thumb => '150x150>',
20
+ :original => { :geometry => '800>', :watermark_path => "#{Rails.root}/public/images/logo.png" }
21
+ },
22
+ :url => '/assets/attachment/:id/:style/:basename.:extension',
23
+ :path => ':rails_root/public/assets/attachment/:id/:style/:basename.:extension',
24
+ :default_url => "/images/:style/mising.png"
25
+ end
26
+
27
+ ```
28
+
29
+
30
+ ## Installation
31
+
32
+ Install from github:
33
+ ```ruby
34
+ gem 'ack-paperclip-watermark', :github => 'ack43/paperclip-watermark'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle install
40
+
41
+ Or install it yourself as:
42
+ ```ruby
43
+ gem install paperclip-watermark
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/paperclip-watermark'
7
+ t.test_files = FileList['test/lib/paperclip-watermark/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1 @@
1
+ require 'paperclip-watermark'
@@ -0,0 +1,6 @@
1
+ require 'paperclip-watermark/version'
2
+ require 'paperclip-watermark/watermark'
3
+ require 'paperclip-watermark/engine'
4
+
5
+
6
+ module PaperclipWatermark end
@@ -0,0 +1,6 @@
1
+ module PaperclipWatermark
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module PaperclipWatermark
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,125 @@
1
+ # from http://github.com/ng/paperclip-watermarking-app
2
+ # with modifications from http://exviva.posterous.com/watermarking-images-with-rails-3-and-papercli
3
+ # and even more modifications to ensure works with paperclip >= 2.3.8 and rails >= 3
4
+ #
5
+ # Note: In rails 3 paperclip processors are not automatically loaded.
6
+ # You must add the following above your model class definition:
7
+ #
8
+ # require 'paperclip_processors/watermark'
9
+
10
+ module Paperclip
11
+ class Watermark < Processor
12
+ # Handles watermarking of images that are uploaded.
13
+ attr_accessor :current_geometry, :target_geometry,
14
+ :format, :whiny, :convert_options,
15
+ :watermark_path, :position, :overlay, :tile, :watermark_option, :dissolve_option, :watermark_geometry, :watermark_resize
16
+
17
+ def initialize file, options = {}, attachment = nil
18
+ super
19
+ geometry = options[:geometry]
20
+ @crop = geometry[-1,1] == '#' if geometry.present?
21
+
22
+ @file = file
23
+ @target_geometry = Geometry.parse geometry
24
+ @current_geometry = Geometry.from_file @file
25
+
26
+ @convert_options = options[:convert_options]
27
+ @whiny = options[:whiny].nil? ? true : options[:whiny]
28
+ @format = options[:format]
29
+
30
+ @watermark_path = options[:watermark_path]
31
+ @position = options[:watermark_position].nil? ? "Center" : options[:watermark_position]
32
+ @overlay = options[:watermark_overlay].nil? ? true : false
33
+ @tile = options[:watermark_tile].nil? ? false : options[:watermark_tile]
34
+ @watermark_option = options[:watermark_option].nil? ? nil : options[:watermark_option]
35
+ @dissolve_option = options[:dissolve_option].nil? ? nil : options[:dissolve_option]
36
+ @watermark_geometry = options[:watermark_geometry].nil? ? nil : options[:watermark_geometry]
37
+ @watermark_resize = options[:watermark_resize].nil? ? nil : options[:watermark_resize]
38
+
39
+ @current_format = File.extname(@file.path)
40
+ @basename = File.basename(@file.path, @current_format)
41
+ end
42
+
43
+ # TODO: extend watermark
44
+
45
+ # Returns true if the +target_geometry+ is meant to crop.
46
+ def crop?
47
+ @crop
48
+ end
49
+
50
+ # Returns true if the image is meant to make use of additional convert options.
51
+ def convert_options?
52
+ not [*@convert_options].reject(&:blank?).empty?
53
+ end
54
+
55
+ # Performs the conversion of the +file+ into a watermark. Returns the Tempfile
56
+ # that contains the new image.
57
+ def make
58
+ filename = [@basename, @format ? ".#{@format}" : ""].join
59
+ dst = TempfileFactory.new.generate(filename)
60
+
61
+ if watermark_path
62
+ # unless _transformation_command.blank?
63
+ # command = "convert"
64
+ # params = [fromfile]
65
+ # params += transformation_command
66
+ # params << tofile(dst)
67
+ # begin
68
+ # success = Paperclip.run(command, params.flatten.compact.join(" "))
69
+ # rescue Paperclip::Errors::CommandNotFoundError
70
+ # raise Paperclip::Errors::CommandNotFoundError, "There was an error resizing and cropping #{@basename}" if @whiny
71
+ # end
72
+ # end
73
+
74
+ command = "composite"
75
+ params = []
76
+ params += %W[-geometry #{watermark_geometry}] if watermark_geometry
77
+ params += %W[-dissolve #{dissolve_option}] if dissolve_option
78
+ params += %W[-watermark #{watermark_option}] if watermark_option
79
+ if tile
80
+ params += %W[-tile]
81
+ else
82
+ params += %W[-gravity #{position}]
83
+ end
84
+ if watermark_resize
85
+ params += %W[#{"\\( #{watermark_path} -resize #{watermark_resize} \\)"} #{fromfile} #{tofile(dst)}]
86
+ else
87
+ params += %W[#{watermark_path} #{fromfile} #{tofile(dst)}]
88
+ end
89
+ begin
90
+ success = Paperclip.run(command, params.flatten.compact.join(" "))
91
+ rescue Paperclip::Errors::CommandNotFoundError
92
+ raise Paperclip::Errors::CommandNotFoundError, "There was an error processing the watermark for #{@basename}" if @whiny
93
+ end
94
+ end
95
+
96
+ dst
97
+ end
98
+
99
+ def fromfile
100
+ File.expand_path(@file.path)
101
+ end
102
+
103
+ def tofile(destination)
104
+ [@format, File.expand_path(destination.path)].compact.join(':')
105
+ end
106
+
107
+ def transformation_command
108
+ if @target_geometry.present?
109
+ scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
110
+ trans = []
111
+ trans += %W[-resize #{scale}]
112
+ trans += %W[-crop #{crop} +repage] if crop
113
+ trans += [*convert_options] if convert_options?
114
+ else
115
+ scale, crop = @current_geometry.transformation_to(@current_geometry, crop?)
116
+ trans = []
117
+ trans += %W[-resize #{scale}] if scale
118
+ trans += %W[-crop #{crop} +repage] if crop
119
+ trans += [*convert_options] if convert_options?
120
+ end
121
+ trans
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paperclip-watermark/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ack-paperclip-watermark"
8
+ gem.version = PaperclipWatermark::VERSION
9
+ gem.authors = ["Alexander Kiseliev", "Vik Ewoods"]
10
+ gem.email = ["dev@redrocks.pro", "support@voroninstudio.eu"]
11
+ gem.description = %q{Paperclip Watermark processor}
12
+ gem.summary = %q{Paperclip Watermark processor}
13
+ gem.homepage = "http://github.com/ack43/paperclip-watermark"
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
+ gem.add_dependency "rake"
20
+ gem.add_dependency "rails", '>= 4'
21
+ gem.add_dependency "minitest"
22
+ # gem.add_dependency "minitest-reporters"
23
+ gem.add_dependency "paperclip", ">= 2.3.8"
24
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push -u origin master
6
+ rake release
@@ -0,0 +1,10 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe PaperclipWatermark do
4
+
5
+ it "must be defined" do
6
+ PaperclipWatermark::VERSION.wont_be_nil
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'paperclip/processor'
4
+
5
+
6
+ require File.expand_path('../../lib/paperclip-watermark.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ack-paperclip-watermark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ - Vik Ewoods
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: paperclip
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.8
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.3.8
70
+ description: Paperclip Watermark processor
71
+ email:
72
+ - dev@redrocks.pro
73
+ - support@voroninstudio.eu
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - lib/ack-paperclip-watermark.rb
87
+ - lib/paperclip-watermark.rb
88
+ - lib/paperclip-watermark/engine.rb
89
+ - lib/paperclip-watermark/version.rb
90
+ - lib/paperclip-watermark/watermark.rb
91
+ - paperclip-watermark.gemspec
92
+ - release.sh
93
+ - test/lib/paperclip-watermark/version_test.rb
94
+ - test/test_helper.rb
95
+ homepage: http://github.com/ack43/paperclip-watermark
96
+ licenses: []
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Paperclip Watermark processor
118
+ test_files:
119
+ - test/lib/paperclip-watermark/version_test.rb
120
+ - test/test_helper.rb