Magento uses the init function of catalog image class to resize your uploaded product images across several pages -:
For category pages -:
<?php echo $this->helper('catalog/image')->init($_product, 'small_image')
->resize(135, 135);?>
For product pages -:
<?php echo $this->helper('catalog/image')->init($_product, 'image')
->resize(270, 270);?>
For basket/checkout pages
<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75, 75);
Those images get saved at the following location media/catalog/product/cache/ based on the following factors
1) Store - media/catalog/product/cache/1/ - 1 is store ID
2) Image type and size - media/catalog/product/cache/1/small_image/135x135/ - image type could be image, small_image and thumbnail and size could be any numeric value
3) Options chosen for resizing (constrainOnly, keepAspectRatio, keepFrame, keepTransparency, backgroundColor) as explained in the above post by @prince - media/catalog/product/cache/1/small_image/135x135/9df78eab33525d08d6e5fb8d27136e95 - This md5 string is for default resizing 9df78eab33525d08d6e5fb8d27136e95 but based on the options this md5 string could change.
The above is basics around how magento generate those resized or cached images and yes they are not optimised and unfortunately they will require further optimisation which is not possible manually because of the amount images get created on your site based on the above mentioned factors. There are several APIs available to optimise those images like Kraken.io, ImageOptim, Smush.it etc. which you can implement if you have development experience or alternatively you can third party extensions. We use the following plugin on our Magento websites
https://www.scommerce-mage.com/optimize-magento-product-cms-images.html