The cache folder is generated in the method Mage_Catalog_Model_Product_Image::setBaseFile
// build new filename (most important params)
$path = array(
Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
'cache',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
);
if((!empty($this->_width)) || (!empty($this->_height)))
$path[] = "{$this->_width}x{$this->_height}";
// add misk params as a hash
$miscParams = array(
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality
);
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams[] = $this->getWatermarkFile();
$miscParams[] = $this->getWatermarkImageOpacity();
$miscParams[] = $this->getWatermarkPosition();
$miscParams[] = $this->getWatermarkWidth();
$miscParams[] = $this->getWatermarkHeigth();
}
$path[] = md5(implode('_', $miscParams));
The $path variable is an array with all the subfolders.
and it looks something like this
array(
'media/catalog/product', //hardcoded - somehow
'cache', // - hardcoded
'1', //the store id
'image', //the name of the image attribute. can also be `thumbnail`, `small_image` or any other attribute you have
'70x', //the resize value. if you only call ->resize(70) it will be `70x`. if you call ->resize(70, 90) it will be `70x90`.
'asjdalsjdlajsdl', //an md5 hash determined by the values of `_keepAspectRatio`, `_keepFrame`, `_keepTransparency`, `_constrainOnly`, `_backgroundColor`, `_angle`, `_quality` and the watermark file an settings.
)
if you want to change this, you have to override the method mentioned above and change the lines I above.
Check also these answers for additional details:
[EDIT]
If you want images resized to 1200x1200 to be in a certain folder, you can modify
if((!empty($this->_width)) || (!empty($this->_height)))
$path[] = "{$this->_width}x{$this->_height}";
to
if ($this->_width == 1200 && (is_empty($this->_height)) || $this->_height == 1200) {
$path = 'p1/c:/images';
}
elseif((!empty($this->_width)) || (!empty($this->_height))) {
$path[] = "{$this->_width}x{$this->_height}";
}