How to automate image optimization for a wordpress site?

Consider this wordpress based site for an example -

You can use an image CDN like ImageEngine , which will automate the resizing, compression and conversion of image formats for the end users device.

You can implement it in Wordpress with the W3 Total Cache plugin

Or you can use the themes function.php to implement it without a plugin