module

CrImage::Util::Tiling

Image tiling and pattern generation.

Provides tools for creating tiled patterns and seamless textures. Useful for:

  • Creating backgrounds and wallpapers
  • Generating repeating patterns
  • Making seamless textures for 3D graphics
  • Web design and UI backgrounds

Class methods

make_seamless(src : Image, blend_width : Int32 = 0) : RGBA

Creates a seamless tileable pattern from an image.

Blends opposite edges together to eliminate visible seams when the image is tiled. The blend_width controls how much of the edge is blended (larger = smoother transition but more distortion).

Parameters:

  • src : The source image
  • blend_width : Width of edge blending in pixels (0 = auto, 1/8 of smallest dimension)

Returns: A new RGBA image that tiles seamlessly

Raises: ArgumentError if blend_width is too large

Example:

img = CrImage.read("texture.png")
seamless = img.make_seamless
tiled = seamless.tile(4, 4) # No visible seams
Source
tile(src : Image, cols : Int32, rows : Int32) : RGBA

Tiles an image in a grid pattern.

Creates a larger image by repeating the source image in a rectangular grid. Each tile is an exact copy of the source image.

Parameters:

  • src : The source image to tile
  • cols : Number of columns (must be positive)
  • rows : Number of rows (must be positive)

Returns: A new RGBA image with tiled pattern

Raises: ArgumentError if cols or rows are not positive

Example:

img = CrImage.read("tile.png")
tiled = img.tile(3, 3) # 3x3 grid
Source
tile_to_size(src : Image, target_width : Int32, target_height : Int32) : RGBA

Tiles an image to fill specific dimensions.

Repeats the image as many times as needed to cover the target area, cropping the final row/column if they extend beyond the target size. Useful for creating backgrounds and wallpapers.

Parameters:

  • src : The source image to tile
  • target_width : Desired width in pixels (must be positive)
  • target_height : Desired height in pixels (must be positive)

Returns: A new RGBA image with tiled pattern

Raises: ArgumentError if dimensions are not positive

Example:

img = CrImage.read("pattern.png")
background = img.tile_to_size(1920, 1080)
Source