caption_paperclip_processor 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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +23 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/caption_paperclip_processor.gemspec +25 -0
- data/lib/caption_paperclip_processor/version.rb +4 -0
- data/lib/caption_paperclip_processor.rb +110 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzEwYmRiZjY0OTY0OTgwM2NhMjg4ZjExOGVjZTk1MDEzYThhYWZjZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWZkOTI0NGE1MGE1MDdjNTM0YjEyMDZkNGE1Mzc5MDkyNTBkYWIyZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmEwMmJiZGVmNDRmNmM4YmZkM2FlYmJiNmFmODM4MTY1MGZmY2QzMWNmMzJk
|
10
|
+
YjVlMTI0YTcxNjAyNTgwYTRjY2IxZDVmNGZhNDI0NzVhOTI1NmIwODhhNzE5
|
11
|
+
MGZjYmI3ZGQ1NGIyNWMwNTNmNjJhNWFjZmVlODRkNmJhNGY5YTc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWYwMjIxNTZkNDc1MjgxMzJiNzg5YzkyMjg1OTZjODc3OWM4MGIwOTg3ZGVi
|
14
|
+
MTA5NDI2YjU4YzRmMjA5OGUzYTAyMjE4ZDQ5ODU2MzE3Y2JhYTU5YWM0ZjI1
|
15
|
+
NDRlNmViZWFjMzgzMTY3ZjE3MTc0OWJhMDE1ZGU3OWZkNjk3MzU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Shaun Dern
|
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.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# CaptionPaperclipProcessor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'caption_paperclip_processor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install caption_paperclip_processor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class ImageWithCaption < ActiveRecord::Base
|
23
|
+
has_attached_file :image, styles: {
|
24
|
+
geometry: "350x250",
|
25
|
+
processors: [:caption],
|
26
|
+
caption: "Some caption text",
|
27
|
+
position: 'center',
|
28
|
+
interword_spacing: 10,
|
29
|
+
kerning: 2.5,
|
30
|
+
padding_height: 12,
|
31
|
+
padding_width: 26,
|
32
|
+
font: Rails.root.join('app', 'assets', 'fonts', 'someFont.ttf'),
|
33
|
+
font_color: "rgba\\(255,255,255,0.8\\)",
|
34
|
+
caption_background: "gray"
|
35
|
+
}
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
The geometry will be the size of the caption that will fill the caption. Font
|
40
|
+
size will be whatever is 'best fit' into the caption 'box'
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'caption_paperclip_processor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "caption_paperclip_processor"
|
8
|
+
spec.version = CaptionPaperclipProcessor::VERSION
|
9
|
+
spec.authors = ["Shaun Dern"]
|
10
|
+
spec.email = ["shaun@substantial.com"]
|
11
|
+
spec.description = %q{Add captions to images}
|
12
|
+
spec.summary = %q{Add captions to images}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "paperclip", "~> 3.4.0"
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "paperclip"
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
class Caption < Processor
|
5
|
+
|
6
|
+
def initialize file, options = {}, attachment = nil
|
7
|
+
super
|
8
|
+
|
9
|
+
@file = file
|
10
|
+
@format = options[:format]
|
11
|
+
@current_format = File.extname(@file.path)
|
12
|
+
@basename = File.basename(@file.path, @current_format)
|
13
|
+
end
|
14
|
+
|
15
|
+
def make
|
16
|
+
src = @file
|
17
|
+
dst = Tempfile.new([@basename, @format].compact.join("."))
|
18
|
+
dst.binmode
|
19
|
+
|
20
|
+
begin
|
21
|
+
parameters = []
|
22
|
+
parameters << caption_options
|
23
|
+
parameters << caption
|
24
|
+
parameters << ":source"
|
25
|
+
parameters << "+swap"
|
26
|
+
parameters << "-gravity center"
|
27
|
+
parameters << "-composite"
|
28
|
+
parameters << ":dest"
|
29
|
+
|
30
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
31
|
+
|
32
|
+
success = convert(parameters, source: "#{File.expand_path(src.path)}[0]", dest: File.expand_path(dst.path))
|
33
|
+
rescue Cocaine::ExitStatusError => e
|
34
|
+
raise Paperclip::Error, "There was an error processing caption for #{@basename}" if @whiny
|
35
|
+
rescue Cocaine::CommandNotFoundError => e
|
36
|
+
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
|
37
|
+
end
|
38
|
+
|
39
|
+
dst
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def caption_options
|
45
|
+
opts = []
|
46
|
+
opts << caption_background
|
47
|
+
opts << font_color
|
48
|
+
opts << line_height
|
49
|
+
opts << letter_spacing
|
50
|
+
opts << word_spacing
|
51
|
+
opts << position
|
52
|
+
opts << caption_size
|
53
|
+
opts << font
|
54
|
+
opts
|
55
|
+
end
|
56
|
+
|
57
|
+
def caption_background
|
58
|
+
"-background #{background_color}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def background_color
|
62
|
+
@options[:caption_background] || "none"
|
63
|
+
end
|
64
|
+
|
65
|
+
def font_color
|
66
|
+
"-fill #{@options[:font_color]}" if @options[:font_color]
|
67
|
+
end
|
68
|
+
|
69
|
+
def font
|
70
|
+
"-font #{@options[:font]}" if @options[:font]
|
71
|
+
end
|
72
|
+
|
73
|
+
def caption
|
74
|
+
"caption:'#{@options[:caption] || ""}'"
|
75
|
+
end
|
76
|
+
|
77
|
+
def position
|
78
|
+
"-gravity #{@options[:position] || "center"}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def letter_spacing
|
82
|
+
"-kerning #{@options[:kerning] || 1.5}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def word_spacing
|
86
|
+
"-interword-spacing #{@options[:interword_spacing] || 5}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def line_height
|
90
|
+
"-interline-spacing #{@options[:interline_spacing] || 18}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def caption_size
|
94
|
+
"-size #{caption_width}X#{caption_height}"
|
95
|
+
end
|
96
|
+
|
97
|
+
def caption_width
|
98
|
+
width = @options[:geometry].split(/[^\d+]/).first.to_i
|
99
|
+
width -= @options[:padding_width] if @options[:padding_width]
|
100
|
+
width
|
101
|
+
end
|
102
|
+
|
103
|
+
def caption_height
|
104
|
+
height = @options[:geometry].split(/[^\d+]/).last.to_i
|
105
|
+
height -= @options[:padding_height] if @options[:padding_height]
|
106
|
+
height
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: caption_paperclip_processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shaun Dern
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: paperclip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.4.0
|
55
|
+
description: Add captions to images
|
56
|
+
email:
|
57
|
+
- shaun@substantial.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- caption_paperclip_processor.gemspec
|
68
|
+
- lib/caption_paperclip_processor.rb
|
69
|
+
- lib/caption_paperclip_processor/version.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Add captions to images
|
94
|
+
test_files: []
|