Three different methods are used to reduce the file size of an existing photo with minimal loss of quality.
The first of these is to change the form of the photo file.
The second is to change the shape of the photo by resizing its pixels.
The third is to delete unnecessary metadata in the photo.
You can access the codes in the following python files. Related photos posted.