If you have to resize a picture so that its file size does not exceed a given limit, you can use the following simple command line statement (using a program from the ImageMagick suite):
convert picture1.png -define jpeg:extent=4mb picture1.jpg
convert→ use the program ‘convert’ (part of ImageMagick)
define→ add specific global settings used to control coders and image processing operations
jpeg:extent=4mb→ The JPEG encoder will search for the highest compression quality level that results in an output file that does not exceed the value.