class

Gosu::Image

Inherits Reference / Object

Constructors

new(filename : String, retro : Bool = false, tileable : Bool = false)

Loads an image from a file or an Gosu::ImageBlob image.

NOTE: For Windows Bitmap (BMP) images, magenta (FF00FF, often called "magic pink" in this context) is treated as a chroma key and all pixels of that color are automatically rendered fully transparent.

source the filename or RMagick image to load from.

retro if true, the image will not be interpolated when it is scaled up or down. When :retro it set, :tileable has no effect.

tileable if true, the Image will not have soft edges when scaled

See: #load_tiles

See: #from_text NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#tileability Tileability explained in the Gosu Wiki

Source
new(width : Int32, height : Int32, rgba : Bytes, image_flags : UInt32 = Gosu.image_flags)
Source
new(pointer : Pointer(UInt8))
Source

Class methods

from_blob(width : Int32, height : Int32, rgba : Bytes = Bytes.new(0))

Creates a new image with the given dimensions and RGBA pixel data.

width Width of the image in pixels.

height Height of the image in pixels.

rgba A string containing raw binary image data, with one byte ('uint8') per RGBA component.

Source
from_markup(markup : String, line_height : Float64 | Int32, font : String = Gosu.default_font_name, width : Float64 | Int32 = -1, spacing : Float64 | Int32 = 0, align : Symbol = :left, bold : Bool = false, italic : Bool = false, underline : Bool = false, retro : Bool = false) : Gosu::Image

Like #from_text, but supports the following markup tags: bold, italic, and <c=rrggbb>colors</c>.

Source
from_text(text : String, line_height : Float64 | Int32, font : String = Gosu.default_font_name, width : Float64 | Int32 = -1, spacing : Float64 | Int32 = 0, align : Symbol = :left, bold : Bool = false, italic : Bool = false, underline : Bool = false, retro : Bool = false) : Gosu::Image

Creates a reusable image from one or more lines of text.

NOTE: The text is always rendered in white. To draw it in a different color, use the color parameter of {#draw}, et al.

line_height the line height, in pixels.

font the name of a system font, or a path to a TrueType Font (TTF) file. A path must contain at least one '/' character to distinguish it from a system font.

width the width of the image, in pixels. Long lines will be automatically wrapped around to avoid overflow, but overlong words will be truncated. If this option is omitted, lines will not be wrapped, and :align and :spacing will be ignored as well.

spacing the spacing between lines, in pixels.

:align the text alignment, [left, :right, :center, :justify].

retro if true, the image will not be interpolated when it is scaled up or down.

SEE: Gosu::Font

NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki

Source
load_tiles(filename_or_image : String | Gosu::Image, width : Int32, height : Int32, retro : Bool = false, tileable : Bool = false) : Array(Gosu::Image)

Loads an image from a file or an RMagick image, then divides the image into an array of equal-sized tiles.

NOTE: For Windows Bitmap (BMP) images, magenta (FF00FF, often called "magic pink" in this context) is treated as a chroma key and all pixels of that color are automatically rendered fully transparent.

tile_width If positive, this is the width of the individual tiles; if negative, the image is divided into -tile_width columns.

tile_height If positive, this is the height of the individual tiles; if negative, the image is divided into -tile_height rows.

retro if true, the image will not be interpolated when it is scaled up or down. When :retro it set, :tileable has no effect.

tileable if true, the Image will not have soft edges when scaled

NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#tileability Tileability explained in the Gosu Wiki

Source

Instance methods

draw(x : Float64 | Int32, y : Float64 | Int32, z : Float64 | Int32, scale_x : Float64 | Int32 = 1.0, scale_y : Float64 | Int32 = 1.0, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)

Draws the image with its top left corner at (x, y).

x the X coordinate.

y the Y coordinate.

z the Z-order.

scale_x the horizontal scaling factor.

scale_y the vertical scaling factor.

color a Gosu::Color or UInt32

mode [:default, :additive] the blending mode to use.

See draw_rot

See draw_as_quad NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki

Source
draw_as_quad(x1 : Float64 | Int32, y1 : Float64 | Int32, c1 : Gosu::Color | Int64 | UInt32, x2 : Float64 | Int32, y2 : Float64 | Int32, c2 : Gosu::Color | Int64 | UInt32, x3 : Float64 | Int32, y3 : Float64 | Int32, c3 : Gosu::Color | Int64 | UInt32, x4 : Float64 | Int32, y4 : Float64 | Int32, c4 : Gosu::Color | Int64 | UInt32, z : Float64 | Int32, mode : Symbol = :default)

Draws the image as an arbitrary quad. This method can be used for advanced non-rectangular drawing techniques, e.g., faking perspective or isometric projection.

See #draw

See Gosu.draw_quad NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#order-of-corners The order of corners explained in the Gosu Wiki NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki

Source
draw_rot(x : Float64 | Int32, y : Float64 | Int32, z : Float64 | Int32, angle : Float64 | Int32, center_x : Float64 | Int32 = 0.5, center_y : Float64 | Int32 = 0.5, scale_x : Float64 | Int32 = 1, scale_y : Float64 | Int32 = 1, color : Gosu::Color | Int64 | UInt32 = Gosu::Color::WHITE, mode : Symbol = :default)

Draws the image rotated, with its rotational center at (x, y).

center_x the relative horizontal rotation origin.

center_y the relative vertical rotation origin.

See #draw NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#drawing-with-colours Drawing with colors, explained in the Gosu Wiki NOTE: https://github.com/gosu/gosu/wiki/Basic-Concepts#z-ordering Z-ordering explained in the Gosu Wiki

Source
gl_tex_info

Returns an object that holds information about the underlying OpenGL texture and UV coordinates of the image.

NOTE: Some images may be too large to fit on a single texture; this method returns nil in those cases.

See Gosu::GLTexInfo

Source
height

Returns the image's height, in pixels.

Source
insert(other : Gosu::Image, x : Int32 | Float64, y : Int32 | Float64)

Overwrites part of the image with the contents of another. If the source image is partially out of bounds, it will be clipped to fit.

This can be used to e.g. overwrite parts of a landscape.

source the filename, Gosu::Image, or Gosu::ImageBlob image to load from.

x the X coordinate of the top left corner.

y the Y coordinate of the top left corner.

Source
save(filename : String)

Saves the image to a file. The file format is determined from the file extension.

Useful for, e.g., pre-rendering text on a development machine where the necessary fonts are known to be available.

filename the path to save the file under.

Source
subimage(left : Int32, top : Int32, width : Int32, height : Int32) : Gosu::Image

Returns an image that is a smaller, rectangular view of this Gosu::Image.

This is a very fast operation, and no new textures will be allocated. If you update this Gosu::Image or the #subimage using #insert, the other Gosu::Image will be affected as well.

Caveats:

  • If you stretch or rotate a #subimage, the pixels adjacent to it might bleed into it, as Gosu does not manage the 'tileability' of subimages.
Source
to_blob

Returns the associated texture contents as binary string of packed RGBA values.

Source
width

Returns the image's width, in pixels.

Source