This is a fast trick to get all your uploaded product pictures smaller in size. I hope that most of your files are in JPG, this makes it easier because the tool you are going to use will most likely not change extension of the better compressed image file. If it will not then it is a direct replacement… overwrite and you are done.
Yahoo application Smash-It, here is a trick to fool it to process most of your files in easy 8 steps:
- Get Firefox and an add-on YSlow.
- Put this code as images.php in the root of the domain of your store.
- Run the php file, it will list and display all product images on one page.
- On this page run YSlow, go to tools, go to Smash-It, it will load a new page analyzing listed images.
- Wait until all files are done, download the single ZIP file of all newly compressed images, unzip to some temp directory
- Look for files that have changed extensions, like *.gif.png and *.jpg.png or similar
- Delete files if such found in step #6.
8.) Upload to /images/product via FTP
Enjoy smaller loading times even if it is only 5% less. However, images take the largest (like 75%) of html loading time. Depending on your luck, you can save a lot of transfer bandwidth and make your site more snappy.
Code for PHP is below:
```php
$d=dirname(__file__);
$dd='/images/product';
$d.=$dd;
if ($handle = opendir($d)) {
while (false !== ($file = readdir($handle))) {
$t=pathinfo($file);
if(($t['extension']=='gif')||($t['extension']=='png')||($t['extension']=='jpg'))
echo "
$file";
}
closedir($handle);
}
?>
```