Module: Tessel

Defined in:
lib/tessel.rb,
lib/tessel.rb,
lib/tessel/rbgl.rb,
lib/tessel/version.rb,
lib/tessel/quantize.rb,
sig/tessel.rbs

Defined Under Namespace

Modules: BMP, Color, PNG, PPM, Quantize, RBGL Classes: DecodeError, Error, Image, LimitError, UnsupportedError

Constant Summary collapse

SIGNATURE =
"\x89PNG\r\n\x1a\n".b.freeze
VERSION =

Returns:

  • (String)
"0.2.1"

Class Method Summary collapse

Class Method Details

.decode(bytes, **options) ⇒ Object

Raises:



286
287
288
289
290
291
292
293
# File 'lib/tessel.rb', line 286

def decode(bytes, **options)
  bytes = String(bytes).b
  return PNG.decode(bytes, **options) if bytes.start_with?(SIGNATURE)
  return PPM.decode(bytes, **options) if bytes.start_with?("P3", "P6")
  return BMP.decode(bytes, **options) if bytes.start_with?("BM")

  raise UnsupportedError, "unknown image format"
end

.read(path, **options) ⇒ Object



295
296
297
# File 'lib/tessel.rb', line 295

def read(path, **options)
  decode(File.binread(path), **options)
end