I'm polishing up a feature that lets a user upload a photo.
I'm guessing PHP based. Not sure about the GD toolkit, but Imagick/ImageMagick allows you to set the compression level. What I'd do is set a maximum display size (say 600 px width) then do some math against the compression so it equals +- 3MB. Or work it backwards; 3MB/$compression = (w X h).