CrImage::Util::Stacking
Image stacking and comparison utilities.
Provides tools for combining multiple images into layouts for:
- Before/after comparisons
- Image galleries and collages
- Side-by-side analysis
- Grid layouts
Class methods
Creates a before/after comparison with optional divider.
Places two images side by side with optional vertical divider line between them. Perfect for showing image processing results.
Parameters:
before: First image (typically original)after: Second image (typically processed)divider: Whether to draw divider line (default: false)divider_width: Width of divider line in pixels (default: 2)divider_color: Color of divider line (default: light gray)spacing: Pixels between images (default: 10)
Returns: A new RGBA image with comparison layout
Raises: ArgumentError if divider_width is not positive when divider is enabled
Example:
before = CrImage.read("before.jpg")
after = CrImage.read("after.jpg")
comparison = CrImage.compare_images(before, after, divider: true)
Creates a grid layout of images.
Arranges images in a uniform grid with specified number of columns. Each cell is sized to fit the largest image, with smaller images centered.
Parameters:
images: Array of images to arrange (must not be empty)cols: Number of columns (must be positive)spacing: Pixels between cells (default: 10)background: Background color (default: transparent)
Returns: A new RGBA image with grid layout
Raises: ArgumentError if images is empty, cols is not positive, or spacing is negative
Example:
images = [img1, img2, img3, img4]
grid = CrImage.create_grid(images, cols: 2)
Stacks images horizontally (side by side).
Places images next to each other from left to right with configurable spacing and vertical alignment. Height is determined by the tallest image.
Parameters:
images: Array of images to stack (must not be empty)spacing: Pixels between images (default: 0)alignment: Vertical alignment (default: Center)background: Background color (default: transparent)
Returns: A new RGBA image with stacked images
Raises: ArgumentError if images array is empty or spacing is negative
Example:
before = CrImage.read("before.jpg")
after = CrImage.read("after.jpg")
comparison = CrImage.stack_horizontal([before, after])
Stacks images vertically (top to bottom).
Places images on top of each other from top to bottom with configurable spacing and horizontal alignment. Width is determined by the widest image.
Parameters:
images: Array of images to stack (must not be empty)spacing: Pixels between images (default: 0)alignment: Horizontal alignment (default: Center)background: Background color (default: transparent)
Returns: A new RGBA image with stacked images
Raises: ArgumentError if images array is empty or spacing is negative
Example:
img1 = CrImage.read("top.jpg")
img2 = CrImage.read("bottom.jpg")
stacked = CrImage.stack_vertical([img1, img2])