Magento Image URLs in Modules

Ever wondered how image urls are build?

http://somehost/media/catalog/product/cache/0/small_image/225x/9df78eab33525d08d6e5fb8d27136e95/c/o/coalesce.jpg

The highlighted parts are:

  • Base media path (media/catalog/product)
  • ‚cache‘
  • Store ID
  • Type of  image (see attribute)
  • Size of image as WIDTHxHEIGHT. In above case WIDTHx uses the aspect ratio to calculate the second (smaller) side
  • MD5 of image parameters (see Mage_Catalog_Model_Product_Image::setBaseFile for details).
  • First char of filename
  • Second char of filename
  • Filename

The last three parts are the filename of the original image relative to media/catalog/product.

Things to remember:

  • The hash code is generated using image parameters => The same parameters will generate the same hash code.
  • The hash code does not contain any random data
  • The hash code does not contain the filename