Class: Unmagic::Browser::Console::Image

Inherits:
Tagged
  • Object
show all
Defined in:
lib/unmagic/browser/console/values.rb

Overview

Image bytes the renderer should draw in the terminal.

Instance Attribute Summary

Attributes inherited from Tagged

#name

Instance Method Summary collapse

Constructor Details

#initialize(value, name: "screenshot") ⇒ Image

Returns a new instance of Image.

Parameters:

  • value (String)

    PNG bytes

  • name (String) (defaults to: "screenshot")

    a filename stem for the copy written to disk



43
44
45
# File 'lib/unmagic/browser/console/values.rb', line 43

def initialize(value, name: "screenshot")
  super(value, name: name)
end

Instance Method Details

#dimensionsArray(Integer, Integer)?

The image's pixel size, read straight out of the PNG header — the IHDR chunk is always the first one, at a fixed offset.

Returns:

  • (Array(Integer, Integer), nil)

    width and height, or nil if it isn't a PNG



51
52
53
54
55
# File 'lib/unmagic/browser/console/values.rb', line 51

def dimensions
  return nil unless start_with?("\x89PNG\r\n\x1A\n".b)

  byteslice(16, 8)&.unpack("N2")
end

#extensionString

Returns the file extension for the copy written to disk.

Returns:

  • (String)

    the file extension for the copy written to disk



58
59
60
# File 'lib/unmagic/browser/console/values.rb', line 58

def extension
  "png"
end