Skip to content

Commit

Permalink
another alignment pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Jul 4, 2016
1 parent 1e7ad99 commit b485044
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 29 deletions.
54 changes: 54 additions & 0 deletions alignment.htm
@@ -0,0 +1,54 @@
<!--
HOWTO DEBUG ALIGNMENT ISSUES
1) Add IM commands to draw guide lines in 'letter_avatar.fullsize_command'
2) Run 'docker-compose up'
3) Open this file in a web browser
-->
<style>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
img {
width: 360px;
height: 360px;
border-radius: 50%;
}
</style>
<img src=http://localhost:82/v3/letter/0/858c88/360.png>
<img src=http://localhost:82/v3/letter/1/858c88/360.png>
<img src=http://localhost:82/v3/letter/2/858c88/360.png>
<img src=http://localhost:82/v3/letter/3/858c88/360.png>
<img src=http://localhost:82/v3/letter/4/858c88/360.png>
<img src=http://localhost:82/v3/letter/5/858c88/360.png>
<img src=http://localhost:82/v3/letter/6/858c88/360.png>
<img src=http://localhost:82/v3/letter/7/858c88/360.png>
<img src=http://localhost:82/v3/letter/8/858c88/360.png>
<img src=http://localhost:82/v3/letter/9/858c88/360.png>
<img src=http://localhost:82/v3/letter/A/858c88/360.png>
<img src=http://localhost:82/v3/letter/B/858c88/360.png>
<img src=http://localhost:82/v3/letter/C/858c88/360.png>
<img src=http://localhost:82/v3/letter/D/858c88/360.png>
<img src=http://localhost:82/v3/letter/E/858c88/360.png>
<img src=http://localhost:82/v3/letter/F/858c88/360.png>
<img src=http://localhost:82/v3/letter/G/858c88/360.png>
<img src=http://localhost:82/v3/letter/H/858c88/360.png>
<img src=http://localhost:82/v3/letter/I/858c88/360.png>
<img src=http://localhost:82/v3/letter/J/858c88/360.png>
<img src=http://localhost:82/v3/letter/K/858c88/360.png>
<img src=http://localhost:82/v3/letter/L/858c88/360.png>
<img src=http://localhost:82/v3/letter/M/858c88/360.png>
<img src=http://localhost:82/v3/letter/N/858c88/360.png>
<img src=http://localhost:82/v3/letter/O/858c88/360.png>
<img src=http://localhost:82/v3/letter/P/858c88/360.png>
<img src=http://localhost:82/v3/letter/Q/858c88/360.png>
<img src=http://localhost:82/v3/letter/R/858c88/360.png>
<img src=http://localhost:82/v3/letter/S/858c88/360.png>
<img src=http://localhost:82/v3/letter/T/858c88/360.png>
<img src=http://localhost:82/v3/letter/U/858c88/360.png>
<img src=http://localhost:82/v3/letter/V/858c88/360.png>
<img src=http://localhost:82/v3/letter/W/858c88/360.png>
<img src=http://localhost:82/v3/letter/X/858c88/360.png>
<img src=http://localhost:82/v3/letter/Y/858c88/360.png>
<img src=http://localhost:82/v3/letter/Z/858c88/360.png>
71 changes: 42 additions & 29 deletions lib/letter_avatar.rb
Expand Up @@ -18,11 +18,13 @@ def generate_path(letter, size, r, g, b, version = 1)
fullsize_path = temp_path("/#{letter}/#{r}/#{g}_#{b}/full_v#{version}.png")
resized_path = temp_path("/#{letter}/#{r}/#{g}_#{b}/#{size}_v#{version}.png")

return resized_path if File.exist? resized_path
return resized_path if File.exist?(resized_path)

temp_file_path = temp_path("/" << SecureRandom.hex << ".png")
temp_file_dir = File.dirname(temp_file_path)
FileUtils.mkdir_p(temp_file_dir) unless Dir.exists?(temp_file_dir)

if File.exist? fullsize_path
if File.exist?(fullsize_path)
FileUtils.cp(fullsize_path, temp_file_path)
else
`#{fullsize_command(temp_file_path, letter, r, g, b, version)} 2>/dev/null`
Expand All @@ -49,30 +51,39 @@ def v1

def v2
@v2 ||= begin
offsets = Hash.new('-0+0')
offsets['0'] = '+6+0'
offsets['1'] = '+2+0'
offsets['6'] = '+4+0'
offsets['8'] = '+6+0'
offsets['9'] = '+4+0'
offsets['A'] = '+1+0'
offsets['B'] = '+12+0'
offsets['D'] = '+12+0'
offsets['H'] = '+10+0'
offsets['I'] = '+10+0'
offsets['K'] = '+10+0'
offsets['M'] = '+10+0'
offsets['N'] = '+10+0'
offsets['O'] = '+8+0'
offsets['P'] = '+12+0'
offsets['Q'] = '+8+0'
offsets['R'] = '+10+0'
offsets['T'] = '+4+0'
offsets['U'] = '+10+0'
offsets['V'] = '+1+0'
offsets['W'] = '+2+0'
offsets['X'] = '+2+0'
offsets['Y'] = '+2+0'
offsets = Hash.new('-0+5')
offsets['0'] = '+6+5'
offsets['1'] = '+6+5'
offsets['2'] = '+6+5'
offsets['6'] = '+4+5'
offsets['7'] = '+8+5'
offsets['8'] = '+6+5'
offsets['9'] = '+4+5'
offsets['A'] = '+1+5'
offsets['B'] = '+12+5'
offsets['C'] = '+8+5'
offsets['D'] = '+12+5'
offsets['E'] = '+4+5'
offsets['F'] = '+6+5'
offsets['G'] = '+8+5'
offsets['H'] = '+10+5'
offsets['I'] = '+12+5'
offsets['J'] = '+8+5'
offsets['K'] = '+10+5'
offsets['L'] = '+8+5'
offsets['M'] = '+10+5'
offsets['N'] = '+10+5'
offsets['O'] = '+8+5'
offsets['P'] = '+12+5'
offsets['Q'] = '+8+5'
offsets['R'] = '+12+5'
offsets['T'] = '+4+5'
offsets['U'] = '+10+5'
offsets['V'] = '+1+5'
offsets['W'] = '+2+5'
offsets['X'] = '+2+5'
offsets['Y'] = '+2+5'
offsets['Z'] = '+8+5'
["Roboto-Medium", offsets]
end
end
Expand All @@ -82,11 +93,16 @@ def fullsize_command(path, letter, r, g, b, version)

# NOTE: to debug alignment issues, add these lignes before the path
# -fill '#00F'
# -draw "line 0,#{FULLSIZE/2 + FULLSIZE/4} #{FULLSIZE},#{FULLSIZE/2 + FULLSIZE/4}"
# -draw "line 0,#{FULLSIZE/2} #{FULLSIZE},#{FULLSIZE/2}"
# -draw "line 0,#{FULLSIZE/4} #{FULLSIZE},#{FULLSIZE/4}"
# -draw "line #{FULLSIZE/2 + FULLSIZE/4},0 #{FULLSIZE/2 + FULLSIZE/4},#{FULLSIZE}"
# -draw "line #{FULLSIZE/2},0 #{FULLSIZE/2},#{FULLSIZE}"
# -draw "line #{FULLSIZE/4},0 #{FULLSIZE/4},#{FULLSIZE}"

%W{
convert
-depth 8
-dither None
-colors 128
-size #{FULLSIZE}x#{FULLSIZE}
Expand All @@ -96,9 +112,6 @@ def fullsize_command(path, letter, r, g, b, version)
-font '#{font}'
-gravity Center
-annotate #{offsets[letter]} '#{letter}'
-depth 8
-dither None
-colors 128
'#{path}'
}.join(' ')
end
Expand Down

0 comments on commit b485044

Please sign in to comment.