开发者

Adding different thumnail sizes to products in magento

I have a magento store that sells glasses, clothing etc. The problem is that i would like my glasses to have thumbnails that are say 300px X 100px and the clothes to have thumbnails that are 300px X 300px.

I can think of a few different routes I might take but I am unsure of the implications each route would have on the upgradeablity of my store. (currently using Magento 1.4.2 as i dont yet have faith in 1.5.x)

Route 1) Adding Extra image sizes to products

So this route I would somehow add an extra image to my products in the admin area and each product would have a glasses size thumb and a clothing size thumb.

Route 2) Altering the thumbnail size depending开发者_JS百科 on attribute set

I would put some sort of a case statement in the image resizing script to change the size of the thumnail depending on the attribute set the product is using.

If anyone has any other ideas on how this might be accomplished it would be greatly appreciated!


Using different Attribute Set for each of the products (glasses & clothing) is a very good idea for this sort of store. However, you can also try for a separate attribute mentioning the type of product (between glasses & clothing).

Regarding the image resizing, I have found a very easy to use script, whose code is as below:-

public function resizeImage($imageName, $width=NULL, $height=NULL, $imagePath=NULL) {
    $imagePath = str_replace("/", DS, $imagePath);
    $imagePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $imageName;

    if ($width == NULL && $height == NULL) {
        $width = 100;
        $height = 100;
    }
    $resizePath = $width . 'x' . $height;
    $resizePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $resizePath . DS . $imageName;

    if (file_exists($imagePathFull) && !file_exists($resizePathFull)) {
        $imageObj = new Varien_Image($imagePathFull);
        $imageObj->constrainOnly(TRUE);
        $imageObj->keepAspectRatio(TRUE);
        $imageObj->resize($width, $height);
        $imageObj->save($resizePathFull);
    }

    $imagePath = str_replace(DS, "/", $imagePath);
    return Mage::getBaseUrl("media") . $imagePath . "/" . $resizePath . "/" . $imageName;
}

You will definitely need to do some tweaking regarding the different dimensions which you want to provide, but still it's a very good piece of code (available here), which has saved my back many-a-times.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜