From Pixels to Page Boxes
A PDF page is measured in points, 72 per inch, while an image is measured in pixels. Placing a 3000-pixel-wide photo on A4 (595.28 by 841.89 points) at 300 DPI implies a physical width of 10 inches, or 720 points, which overflows the 8.27-inch page. The layout engine therefore fits the image: contain keeps everything visible, cover fills and crops, and actual size may overflow.
Each image becomes an XObject with /Width, /Height, /BitsPerComponent, /ColorSpace and a filter. The page content stream uses cm to scale the unit square to the target rectangle and Do to paint it. /MediaBox and /CropBox define the page size, and margins shrink the content rectangle rather than the paper.