avatar_magick 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +119 -0
- data/Rakefile +1 -0
- data/avatar_magick.gemspec +25 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/avatar_magick.rb +8 -0
- data/lib/avatar_magick/generators/initial_avatar.rb +52 -0
- data/lib/avatar_magick/plugin.rb +11 -0
- data/lib/avatar_magick/version.rb +3 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0116fa0760d83021b28806d0396bcf1a21d14092
|
4
|
+
data.tar.gz: bba762c915327a2e835e3ae3c4846dbf5810d9a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de284e1d3468560cecf4183309b8db9b70c524c5d576c6822a36439f0390d6c6547cbf2b21627c145e44ea9980109b5fde653113a2a4e637de12e11e16dafcff
|
7
|
+
data.tar.gz: 76b249f04b4627d6746d98934fa5f772a793b06730ce94989ed9a42b86f03603216e5372db703ff6896833bbb53fa702bf8898a0abfc899dcdd319dcf76d271e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
## Overview
|
2
|
+
|
3
|
+
AvatarMagick is a [Dragonfly](https://github.com/markevans/dragonfly) plugin for generating Gmail style avatars like those pictured below
|
4
|
+
|
5
|
+
<p align="center">
|
6
|
+
<img src="https://dl.dropboxusercontent.com/u/362501/avatarmagic-github-readme.png" alt="sample">
|
7
|
+
</p>
|
8
|
+
|
9
|
+
The plugin is configurable and options can be set to control background color, text color, font, and size.
|
10
|
+
|
11
|
+
#### Dragonfly compatibility
|
12
|
+
|
13
|
+
The plugin works with the latest versions (1.x) of Dragonfly with support for older versions (0.9.x) in the pipeline.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
It is assumed you're already using Dragonfly. To install AvatarMagick, simply add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'avatar_magick'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Once installed, you'll need to register the AvatarMagick plugin along with the [ImageMagick](http://markevans.github.io/dragonfly/imagemagick/) plugin that's included with the Dragonfly gem.
|
28
|
+
|
29
|
+
#### Rails
|
30
|
+
|
31
|
+
If you're using Dragonfly within your Rails application, you'll already have a `config/initializers/dragonfly.rb` file where your Dragonfly configuration settings are stored. Edit the file and add the following directly below the `plugin :imagemagick` line
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
plugin :avatarmagick
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Sinatra/Rack/Other
|
38
|
+
|
39
|
+
Simply add the plugin within the `configure` block
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'dragonfly'
|
43
|
+
|
44
|
+
Dragonfly.app.configure do
|
45
|
+
plugin :imagemagick
|
46
|
+
plugin :avatarmagick
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
Once the plugin is installed and registered, you can use it like any of the other built-in generators (text, plain, etc.)
|
53
|
+
|
54
|
+
#### Basic
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
image = Dragonfly.app.generate(:initial_avatar, "Bart Jedrocha")
|
58
|
+
```
|
59
|
+
|
60
|
+
will produce
|
61
|
+
|
62
|
+
![basic](https://dl.dropboxusercontent.com/u/362501/avatarmagick-readme-basic.png)
|
63
|
+
|
64
|
+
The plugin will extract at most 3 initials from the passed-in string (e.g. Bill James Pheonix MacKenzie will produce an avatar with the initials BJP). This should be sufficient for the vast majority of cases.
|
65
|
+
|
66
|
+
#### Playing with options
|
67
|
+
|
68
|
+
You can pass options to control the background color, text color, size, and font used to generate the avatar
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Dragonfly.app.generate(:initial_avatar, "Martin", {background_color: 'ff8f00'})
|
72
|
+
```
|
73
|
+
|
74
|
+
will produce
|
75
|
+
|
76
|
+
![bgcolor](https://dl.dropboxusercontent.com/u/362501/avatarmagick-readme-bgcolor.png)
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
Dragonfly.app.generate(:initial_avatar, "James Hetfield", {background_color: 'f48fb1', color: '333333'})
|
80
|
+
```
|
81
|
+
|
82
|
+
will produce
|
83
|
+
|
84
|
+
![txtcolor](https://dl.dropboxusercontent.com/u/362501/avatarmagick-readme-textcolor.png)
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
Dragonfly.app.generate(:initial_avatar, "Amanda Smith", {background_color: '00695c', size: '200'})
|
88
|
+
```
|
89
|
+
|
90
|
+
will produce
|
91
|
+
|
92
|
+
![size](https://dl.dropboxusercontent.com/u/362501/avatarmagick-readme-size.png)
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
Dragonfly.app.generate(:initial_avatar, "Oliver Murphy", {background_color: 'b71c1c', font: 'Georgia'})
|
96
|
+
```
|
97
|
+
|
98
|
+
will produce
|
99
|
+
|
100
|
+
![font](https://dl.dropboxusercontent.com/u/362501/avatarmagick-readme-font.png)
|
101
|
+
|
102
|
+
## Development
|
103
|
+
|
104
|
+
After checking out the repo, run `bash bin/setup` to install dependencies. Then, run `ruby bin/console` for an interactive prompt that will allow you to experiment. Please note that before being able to use the generator, you'll need to register both the [ImageMagick](http://markevans.github.io/dragonfly/imagemagick/) plugin and the AvatarMagic plugin
|
105
|
+
|
106
|
+
irb > Dragonfly.app.configure do
|
107
|
+
irb > plugin :imagemagick
|
108
|
+
irb > plugin :avatarmagick
|
109
|
+
irb > end
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
1. Fork it ( https://github.com/[my-github-username]/avatar_magick/fork )
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -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 'avatar_magick/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "avatar_magick"
|
8
|
+
spec.version = AvatarMagick::VERSION
|
9
|
+
spec.authors = ["Bart Jedrocha"]
|
10
|
+
spec.email = ["bart.jedrocha@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Dragonfly Plugin for generating on-the-fly Gmail style avatars}
|
13
|
+
spec.homepage = "https://github.com/bjedrocha/avatar_magick"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
23
|
+
|
24
|
+
spec.add_dependency "dragonfly", "~> 1.0"
|
25
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "avatar_magick"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require "dragonfly"
|
2
|
+
require "avatar_magick/version"
|
3
|
+
require "avatar_magick/plugin"
|
4
|
+
|
5
|
+
# registers AvatarMagick as a plugin using both notations to remain consistent
|
6
|
+
# with the ImageMagick plugin
|
7
|
+
Dragonfly::App.register_plugin(:avatar_magick) { AvatarMagick::Plugin.new }
|
8
|
+
Dragonfly::App.register_plugin(:avatarmagick) { AvatarMagick::Plugin.new }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "dragonfly/hash_with_css_style_keys"
|
2
|
+
|
3
|
+
module AvatarMagick
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
# Generates an initials avatar by extracting the first letter of
|
7
|
+
# the first 3 words in string. Can be customized with background color,
|
8
|
+
# text color, font, and size.
|
9
|
+
class InitialAvatar
|
10
|
+
def call(content, string, opts={})
|
11
|
+
opts = ::Dragonfly::HashWithCssStyleKeys[opts]
|
12
|
+
args = []
|
13
|
+
|
14
|
+
# defaults
|
15
|
+
format = opts[:format] || :png
|
16
|
+
background = opts[:background_color] ? "##{opts[:background_color]}" : '#000000'
|
17
|
+
color = opts[:color] ? "##{opts[:color]}" : '#FFFFFF'
|
18
|
+
size = opts[:size] || '120x120'
|
19
|
+
font = opts[:font] || 'Arial-Regular'
|
20
|
+
|
21
|
+
# extract the first letter of the first 3 words and capitalize
|
22
|
+
text = (string.split(/\s/)- ["", nil]).map { |t| t[0].upcase }.slice(0, 3).join('')
|
23
|
+
|
24
|
+
w, h = size.split('x').map { |d| d.to_i }
|
25
|
+
h ||= w
|
26
|
+
|
27
|
+
font_size = ( w / [text.length, 2].max ).to_i
|
28
|
+
|
29
|
+
# Settings
|
30
|
+
args.push("-gravity Center")
|
31
|
+
args.push("-antialias")
|
32
|
+
args.push("-pointsize #{font_size}")
|
33
|
+
args.push("-font \"#{font}\"")
|
34
|
+
args.push("-family '#{opts[:font_family]}'") if opts[:font_family]
|
35
|
+
args.push("-fill #{color}")
|
36
|
+
args.push("-background #{background}")
|
37
|
+
args.push("label:#{text}")
|
38
|
+
|
39
|
+
content.generate!(:convert, args.join(' '), format)
|
40
|
+
|
41
|
+
args = args.slice(0, args.length - 2)
|
42
|
+
args.push("-size #{w}x#{h}")
|
43
|
+
args.push("xc:#{background}")
|
44
|
+
args.push("-annotate 0x0 #{text}")
|
45
|
+
|
46
|
+
content.generate!(:convert, args.join(' '), format)
|
47
|
+
|
48
|
+
content.add_meta('format' => format, 'name' => "text.#{format}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "avatar_magick/generators/initial_avatar"
|
2
|
+
|
3
|
+
module AvatarMagick
|
4
|
+
|
5
|
+
# Registers the initial_avatar generator
|
6
|
+
class Plugin
|
7
|
+
def call(app, opts={})
|
8
|
+
app.add_generator :initial_avatar, AvatarMagick::Generators::InitialAvatar.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: avatar_magick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bart Jedrocha
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dragonfly
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- bart.jedrocha@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- avatar_magick.gemspec
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/avatar_magick.rb
|
86
|
+
- lib/avatar_magick/generators/initial_avatar.rb
|
87
|
+
- lib/avatar_magick/plugin.rb
|
88
|
+
- lib/avatar_magick/version.rb
|
89
|
+
homepage: https://github.com/bjedrocha/avatar_magick
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A Dragonfly Plugin for generating on-the-fly Gmail style avatars
|
112
|
+
test_files: []
|