Image Merging Principle
Image merging combines multiple images into one according to a specified layout. Horizontal merge: calculate total width (sum of all image widths + spacing) and max height; vertical merge: calculate max width and total height (sum of all image heights + spacing); grid merge: arrange by rows and columns, calculate grid dimensions. Uses Canvas API's drawImage() method to draw each image to target position, supports custom spacing and background color.