Lossless image optimization