tario / imageruby

flexible and easy to use ruby gem for image processing
http://tario.github.com/imageruby/doc/
GNU General Public License v3.0
16 stars 1 forks source link

UTF-8 Encoding strange error #8

Closed tario closed 11 years ago

tario commented 11 years ago

This code fails:

require 'ImageRuby'
include ImageRuby

activeSprite = Image.new(12,12, Color.blue)
img = Image.new(128, 12, Color.coerce("#a8a8a8"))
img.draw!(0,0, activeSprite)

Backtrace:

ArgumentError: invalid byte sequence in UTF-8
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:154:in `ord'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:154:in `block (2 levels) in draw!'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:151:in `each'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:151:in `block in draw!'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:145:in `each'
from /usr/local/xxxxxxxxx/ruby/2.0.0-p247/lib/ruby/gems/2.0.0/gems/imageruby-0.2.4/lib/imageruby/pureruby.rb:145:in `draw!'
from (irb):5
from /usr/local/bin/irb:12:in `<main>
tario commented 11 years ago

This would fix by forcing the encoding, example:

"\xff".ord # throws ArgumentError: invalid byte sequence in UTF-8
"\xff".force_encoding("ascii-8bit").ord # returns 255 as expected 

Or even better: use "binary" encoding (is an alias for the same!)

tario commented 11 years ago

Fixed for released version 0.2.5