Compression rewrites the bytes; it does not promise a smaller file
JPEG and WebP quantize. The quality number changes the step size of that rounding, so high-frequency detail goes first and the byte count usually falls. It does not set the pixel count, and the same number is not the same table in JPEG and WebP. A longest-edge cap is a different operation: it scales both axes so the longer side fits, then the codec encodes that new grid. Exact width and height belong in image resize. The bytes can also be written out as text with image to Base64.
What quality, the sample grid, and the byte count each change
Why the quality number is a quantization step, not a share of the file
- Baseline JPEG splits the picture into 8×8 blocks, runs a DCT, then rounds the coefficients with a quantization table.
- The quality control scales that table. A coarser step zeros high-frequency coefficients first: fine texture and weak edges.
- 100 is still lossy. Chroma is often subsampled, commonly 4:2:0, even at the top of the scale.
- WebP has its own tables. JPEG 80 and WebP 80 are not the same step, so the byte counts are not interchangeable.
Why a PNG often stays large when a photo is “compressed”
- PNG stores filtered pixels and then DEFLATE. For those pixels the encode is lossless.
- There is no JPEG-style quality step, so a quality control does not apply to PNG.
- A photograph is noisy and hard to predict, so DEFLATE saves little and a photo PNG is often several times a JPEG.
- Flat color, screenshots, and line art predict well, which is why those pictures stay small as PNG. Moving a photo to JPEG or WebP drops alpha.
Why a longest-edge cap resamples the grid instead of cropping it
- The cap looks at the longer of width and height. If that side is already within the cap, the grid stays put.
- If it is longer, both axes share one scale so the long side lands on the cap. The aspect ratio stays. Corners are not cut off.
- Rounding to whole pixels can leave the result a sample off the exact ratio.
- The new grid is then quantized if the codec is JPEG or WebP. Fewer samples and coarser steps are two separate losses.
Why encoding again can make the file larger
- A JPEG is decoded to pixels that already include the old rounding, then encoded with a new table. That is a second generation.
- A file that was already tightly quantized can grow, and the blocks can become easier to see. The extra bytes are not extra detail.
- PNG to PNG can move either way, because the filters and the DEFLATE settings need not match the previous encoder.
- Enlarging the grid and then encoding adds samples. More samples usually mean more bytes, not a sharper photograph.
Where the codec and the container are not the same problem
A page budget that counts bytes, not pixels
A 4000×3000 JPEG can miss a byte budget even when the layout only shows it at 800 pixels wide. Lowering quality keeps the sample grid and spends fewer bits on high frequencies. Capping the long edge changes the grid first. The two do not substitute for each other.
An iPhone still that is still HEVC in a HEIF box
HEIC is not a JPEG bitstream, so there is no JPEG quantization table to coarsen until the still is decoded and written as JPEG. That step is HEIC to JPG. The JPEG that comes out can then be quantized further.