Note that there are some explanatory texts on larger screens.

plurals
  1. POErrors while trying to use RMagik on Heroku
    primarykey
    data
    text
    <p>I'm newer to working in ruby, rails, heroku and even newer to RMagick. I've attempted several solutions to using RMagick on Heroku found on stack overflow with no results. Here is an interesting road block that I've come across. </p> <p>I've created a working function to determine the proper font size to be modified only if the text goes beyond a given length. Everything works beautifully on my local machine. However, once attempted on heroku it seems as though the RMagick is either not install or not being recognized. It looks as thought the heroku console references ruby 1.9.1, does this have anything to do with it? I'm continuing to research the issue, but would be interested if anyone has any thoughts on the matter.</p> <p>Many Thanks</p> <p><em><strong></em>*LOCAL MACHINE RUBY 1.8.7 RAILS CONSOLE***</strong></p> <pre><code>1.8.7 :001 &gt; def find_width(string, typeface, font_size) 1.8.7 :002?&gt; max_width = 1087 1.8.7 :003?&gt; type_size = font_size.to_i 1.8.7 :004?&gt; label = Magick::Draw.new 1.8.7 :005?&gt; label.font = typeface 1.8.7 :006?&gt; label.pointsize = type_size 1.8.7 :007?&gt; label.text_antialias(true) 1.8.7 :008?&gt; label.text(0,0,string) 1.8.7 :009?&gt; metrics = label.get_type_metrics(string) 1.8.7 :010?&gt; width = metrics.width 1.8.7 :011?&gt; if width &gt; max_width 1.8.7 :012?&gt; adjusted_size = type_size * max_width / width 1.8.7 :013?&gt; return adjusted_size.to_i 1.8.7 :014?&gt; else 1.8.7 :015 &gt; return font_size 1.8.7 :016?&gt; end 1.8.7 :017?&gt; end =&gt; nil 1.8.7 :018 &gt; find_width("HI", "blackjar-webfont", "263pt") =&gt; "263pt" 1.8.7 :019 &gt; find_width("This is a test!", "blackjar-webfont", "263pt") =&gt; 185 1.8.7 :020 &gt; </code></pre> <hr> <p><em><strong></em>*LOCAL MACHINE RUBY 1.9.2 RAILS CONSOLE***</strong></p> <pre><code>Loading development environment (Rails 3.0.7) 1.9.2p290 :001 &gt; def find_width(string, typeface, font_size) 1.9.2p290 :002?&gt; max_width = 1087 1.9.2p290 :003?&gt; type_size = font_size.to_i 1.9.2p290 :004?&gt; label = Magick::Draw.new 1.9.2p290 :005?&gt; label.font = typeface 1.9.2p290 :006?&gt; label.pointsize = type_size 1.9.2p290 :007?&gt; label.text_antialias(true) 1.9.2p290 :008?&gt; label.text(0,0,string) 1.9.2p290 :009?&gt; metrics = label.get_type_metrics(string) 1.9.2p290 :010?&gt; width = metrics.width 1.9.2p290 :011?&gt; if width &gt; max_width 1.9.2p290 :012?&gt; adjusted_size = type_size * max_width / width 1.9.2p290 :013?&gt; return adjusted_size.to_i 1.9.2p290 :014?&gt; else 1.9.2p290 :015 &gt; return font_size 1.9.2p290 :016?&gt; end 1.9.2p290 :017?&gt; end =&gt; nil 1.9.2p290 :018 &gt; find_width("HI", "blackjar-webfont", "263pt") =&gt; "263pt" 1.9.2p290 :019 &gt; find_width("This is a test!", "blackjar-webfont", "263pt") =&gt; 185 1.9.2p290 :020 &gt; </code></pre> <hr> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em></strong><em>HEROKU CONSOLE</em><strong><em>*</em>**<em>*</em>**<em>*</em>****</strong></p> <pre><code>Loading production environment (Rails 3.0.7) irb(main):001:0&gt; def find_width(string, typeface, font_size) irb(main):002:1&gt; max_width = 1087 irb(main):003:1&gt; type_size = font_size.to_i irb(main):004:1&gt; label = Magick::Draw.new irb(main):005:1&gt; label.font = typeface irb(main):006:1&gt; label.pointsize = type_size irb(main):007:1&gt; label.text_antialias(true) irb(main):008:1&gt; label.text(0,0,string) irb(main):009:1&gt; metrics = label.get_type_metrics(string) irb(main):010:1&gt; width = metrics.width irb(main):011:1&gt; if width &gt; max_width irb(main):012:2&gt; adjusted_size = type_size * max_width / width irb(main):013:2&gt; return adjusted_size.to_i irb(main):014:2&gt; else irb(main):015:2* return font_size irb(main):016:2&gt; end irb(main):017:1&gt; end =&gt; nil irb(main):018:0&gt; find_width("HI", "blackjar-webfont", "263pt") NameError: uninitialized constant Magick from /app/vendor/bundle/ruby/1.9.1/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library' from (irb):4:in `find_width' from (irb):18 from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start' from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start' from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:23:in `&lt;top (required)&gt;'from script/rails:6:in `require'from script/rails:6:in `&lt;main&gt;' irb(main):019:0&gt; </code></pre> <hr> <p>Function Code</p> <pre><code>def find_width(string, typeface, font_size) max_width = 1087 type_size = font_size.to_i label = Magick::Draw.new label.font = typeface label.pointsize = type_size label.text_antialias(true) label.text(0,0,string) metrics = label.get_type_metrics(string) width = metrics.width if width &gt; max_width adjusted_size = type_size * max_width / width return adjusted_size.to_i else return font_size end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload