Move jpeg optim to a function.