Resizing changes the sample grid, then a codec writes new bytes
Pixel width and height count samples. Resampling builds a new grid: enlarging interpolates samples that were not captured, and shrinking folds several samples into one. The aspect ratio is width divided by height. Locking it keeps both axes on that same scale, so a circle stays a circle. JPEG or WebP then quantizes the new samples; PNG stores those samples without a second lossy step. Byte size is a different ledger — compare it in the image compressor, or turn the bytes into text with image to Base64.
What width, height, and a new encode actually change
Why pixel width and height are a sample grid, not a length in centimeters
- The file’s width and height count samples across and down. They are not centimeters.
- Print size is that count divided by a density, often pixels per inch. 1800×1200 at 300 ppi is about 6×4 inches.
- The same samples at 72 ppi describe a larger print. The grid itself did not gain detail.
- A canvas re-encode usually drops the old EXIF and density tag, so a reader falls back to its own default density.
Why a locked aspect ratio forces both axes to share one scale factor
- Aspect ratio is width divided by height. A 1600×900 picture is 16:9.
- With the lock on, the other side is original opposite side times the new side, divided by the original side.
- That quotient is rounded to a whole pixel, so the result can be off by one sample.
- Unlocking lets the two scale factors differ. The picture is resampled into a new rectangle and looks stretched. The lock does not crop or pad.
Why enlarging invents samples and shrinking throws high frequencies away
- Upscaling inserts samples between the ones the camera captured. Interpolation cannot recover detail that was never stored.
- A soft kernel blurs edges. A sharper kernel can ring. Either way the information ceiling is the smaller grid.
- Downscaling packs several samples into one. Edges and text thinner than the new cell are mixed away or lost.
- Enlarging afterward does not restore those frequencies. A GIF is a sequence of frames; one raster encode keeps a single frame.
Why the file’s byte size does not scale with the number of pixels
- JPEG and WebP quantize. The quality number changes the step size, not the pixel count. 100 is still lossy.
- PNG is lossless for the resampled pixels. The resample itself has already replaced the old grid.
- JPEG has no alpha. Transparent pixels become opaque, commonly against black. PNG and WebP can keep alpha.
- A noisy small PNG can outweigh a smooth large JPEG. Pixel count and byte count are separate accounts.
Where the sample grid and the container part ways
A layout that needs a fixed pixel box
A slot of 1200×630 still holds whatever samples you give it, scaled by CSS. Resampling to that box changes the stored grid. CSS scaling does not. If the two scale factors differ, the picture stretches; a locked ratio keeps the original rectangle.
An iPhone still that is still a HEIF container
HEIC is HEVC inside HEIF. A decoder that only knows JPEG, PNG, GIF, and WebP never obtains that sample grid, so there is no width or height to recompute. The still has to be decoded and written as JPEG first, which is what HEIC to JPG does.