Automatic image optimisation, image galleries and more

Have you found a way to do this programmatically?