Skip to content

Commit

Permalink
Remove image_optim dependency;
Browse files Browse the repository at this point in the history
- Fix text render position in center;
- Remove special font name in convert command, let it use the default font for compatible different OS.
  • Loading branch information
huacnlee committed Oct 28, 2015
1 parent 9acd93e commit 9464320
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ Code extracted from discourse source (thanks guys!) - I needed this functionalit

System requirements

sudo apt-get install -y advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush pngquant
sudo apt-get install -y imagemagick

Add this line to your application's Gemfile:

Expand Down
3 changes: 1 addition & 2 deletions letter_avatar.gemspec
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.summary = %q{Create nice initals avatars from your users usernames}
spec.homepage = "https://github.com/ksz2k/letter_avatar"
spec.license = "GPL"

spec.rubyforge_project = "letter_avatar"

spec.files = `git ls-files`.split($/)
Expand All @@ -22,5 +22,4 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "image_optim"
end
2 changes: 1 addition & 1 deletion lib/letter_avatar.rb
@@ -1,5 +1,6 @@
require "letter_avatar/version"
require "letter_avatar/avatar"
require "letter_avatar/avatar_helper"

module LetterAvatar

Expand Down Expand Up @@ -27,7 +28,6 @@ def self.resize(from, to, width, height)
`convert #{instructions}`

if $?.exitstatus == 0
ImageOptim.new.optimize_image(to) rescue nil
true
else
false
Expand Down
5 changes: 1 addition & 4 deletions lib/letter_avatar/avatar.rb
Expand Up @@ -71,17 +71,14 @@ def generate_fullsize(identity)
-pointsize 200
-fill white
-gravity Center
-font 'Helvetica'
-stroke #{to_rgb(stroke)}
-strokewidth 2
-annotate -5+25 '#{letter}'
-annotate -5+40 '#{letter}'
'#{filename}'
}

`convert #{instructions.join(" ")}`

ImageOptim.new.optimize_image(filename) rescue nil

filename
end

Expand Down
22 changes: 12 additions & 10 deletions lib/letter_avatar/avatar_helper.rb
@@ -1,16 +1,18 @@
# encoding: UTF-8
module LetterAvatar::AvatarHelper
module LetterAvatar
module AvatarHelper

def letter_avatar_for(name, size = 64)
LetterAvatar.generate(name, size)
end
def letter_avatar_for(name, size = 64)
LetterAvatar.generate(name, size)
end

def letter_avatar_url_for(avatar_path)
avatar_path.to_s.gsub(/public/,'')
end
def letter_avatar_url_for(avatar_path)
avatar_path.to_s.sub('public/','/')
end

def letter_avatar_tag(name, size = 64, options = {})
image_tag(letter_avatar_url_for(letter_avatar_for(name, size)), options)
end
def letter_avatar_tag(name, size = 64, options = {})
image_tag(letter_avatar_url_for(letter_avatar_for(name, size)), options)
end

end
end

0 comments on commit 9464320

Please sign in to comment.