I am working on magento 1.9 installation. I need to optimize images before/at the time of page loading. I have refered so many php scripts for this, http://zenverse.net/php-reducing-image-filesize-using-gd/ - I found this much better option. But it cannot create image from the image url. The error log says:
ERR (3): Warning: imagejpeg(): Unable to open 'http://mydomain/media/catalog/product/cache/3/small_image/180x180/9df785d08d6e5fb8d27136e95/4/8461c5c67fab50b68781772a4df.jpg' for writing: No such file or directory.
The function compress_image($source_url, $destination_url, $quality) works properly for local images. I searched on net for the issue, it says I need to pass relative url. I tried so many times but noting worked. My code in list.phtml:
<?php /* Display optimised images */
$img = $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgX, $imgY);
$imgsrc = Mage::helper('featured')->compress_image($img, $img, 90);
?>
<img src="<?php echo $imgsrc; ?> " width="<?php echo $imgX; ?>" height=" <?php echo $imgY; ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
I dont know what I am missing. Thanks in advance.