Visa application photos go through more than a simple file upload. Many portals run automated checks on the image itself, comparing head position, background color and facial features against biometric standards before the application is even submitted for review. The strict file size cap exists partly for storage reasons and partly because these checks need a predictable, uncompressed-enough image to run against. A photo that passed visual inspection but arrives heavily compressed can still fail the automated biometric check even though it looks fine to a human.
The DS-160 system used for US visas is the strictest example of this. It enforces a 240KB hard ceiling and checks pixel dimensions, color space and file format all in the same automated pass, rejecting the upload immediately if any one of these fails. Schengen and UK systems are generally more forgiving on file size but still expect a clean JPEG without heavy compression artifacts around the face.
File size and photo dimensions are separate requirements
It is easy to assume that compressing a photo down to a target kilobyte count also takes care of the pixel dimensions a portal asks for, but these are two different requirements handled by two different steps. A US visa photo needs to be square and between 600 and 1200 pixels per side. A Schengen or UK visa photo is printed at 35mm by 45mm. Compressing alone does not create that square crop or that print ratio, it only reduces the file's byte size while keeping whatever dimensions the photo already had. If your portal states both a pixel requirement and a file size limit, handle the dimensions first with a crop or resize step, then compress the result to fit the file size limit.
The HEIC problem for iPhone applicants
A large share of visa photo upload failures trace back to format rather than size. iPhones save photos as HEIC by default, and DS-160 along with most other government visa systems only accept JPEG. The rejection message this produces often looks identical to a size rejection, which sends people compressing an image that was never going to be accepted regardless of size. This tool decodes HEIC input and always outputs JPEG, so the format issue is resolved automatically whether or not it was the actual cause of a previous rejection.