module

CrImage::Util

Class methods

thumbnail(img : Image, width : Int32, height : Int32, mode : ThumbnailMode = ThumbnailMode::Fit, quality : ResampleQuality = ResampleQuality::Bicubic) : RGBA

Generates a thumbnail from an image with specified dimensions and quality.

Creates a resized version of the image suitable for thumbnails, previews, and web display. Supports different scaling modes and quality levels.

Parameters:

  • img : The source image
  • width : Target width in pixels (must be positive)
  • height : Target height in pixels (must be positive)
  • mode : Scaling mode (default: Fit)
  • quality : Resampling quality (default: Bicubic)

Returns: A new RGBA thumbnail image

Raises: ArgumentError if dimensions are not positive

Example:

img = CrImage.read("photo.jpg")
thumb = CrImage::Util.thumbnail(img, 200, 200, ThumbnailMode::Fill)
Source
watermark_image(img : Image, watermark : Image, options : WatermarkOptions) : RGBA

Adds an image watermark to an image.

Overlays a watermark image onto the source image with configurable position, opacity, and tiling. Useful for copyright protection and branding.

Parameters:

  • img : The source image
  • watermark : The watermark image to overlay
  • options : Watermark configuration options

Returns: A new RGBA image with watermark applied

Raises: ArgumentError if opacity is outside 0.0-1.0 range

Example:

img = CrImage.read("photo.jpg")
logo = CrImage.read("logo.png")
opts = CrImage::Util::WatermarkOptions.new(opacity: 0.3)
watermarked = CrImage::Util.watermark_image(img, logo, opts)
Source
watermark_text(img : Image, text : String, font_face : Font::Face, options : WatermarkOptions) : RGBA

Adds a text watermark to an image.

Renders text onto the image with configurable position, opacity, and tiling. Useful for copyright notices, timestamps, and branding.

Parameters:

  • img : The source image
  • text : The text to render (must not be empty)
  • font_face : Font face for text rendering
  • options : Watermark configuration options

Returns: A new RGBA image with text watermark applied

Raises: ArgumentError if opacity is invalid or text is empty

Example:

img = CrImage.read("photo.jpg")
font = FreeType::TrueType.load("font.ttf")
face = FreeType::TrueType.new_face(font, 24.0)
opts = CrImage::Util::WatermarkOptions.new(opacity: 0.5)
watermarked = CrImage::Util.watermark_text(img, "© 2024", face, opts)
Source

Nested types