Optimize images using lossy and lossless algorithms