Save the image as jpeg.
where the image is saved
save quality(%)
save as a progressive JPEG file
for SubSampling4ab, save with 4:a:b
On saving, compute optimal Huffman coding tables (can reduce a few percent of file size)
Save basic JPEG, without metadata or any markers
See Implementation
Save the image as jpeg.