向 magento 中的产品添加不同的缩略图大小

发布于 2024-10-20 01:04:55 字数 420 浏览 2 评论 0原文

我有一家销售眼镜、服装等的 magento 商店。问题是我希望我的眼镜有 300px X 100px 的缩略图,而衣服有 300px X 300px 的缩略图。

我可以想到一些可能采取的不同路线,但我不确定每条路线对我商店的可升级性有何影响。 (目前使用 Magento 1.4.2,因为我对 1.5.x 还没有信心)

路线 1)向产品添加额外的图像尺寸

所以这条路线我会以某种方式在管理中向我的产品添加额外的图像区域和每个产品都有一个眼镜尺寸的拇指和一个衣服尺寸的拇指。

路线 2)根据属性集更改缩略图大小

我会在图像大小调整脚本中放置某种 case 语句,以根据产品使用的属性集更改缩略图的大小。

如果有人对如何实现这一点有任何其他想法,我们将不胜感激!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-10-27 01:04:55

对于此类商店来说,为每种产品(眼镜和服装)使用不同的属性集是一个非常好的主意。不过,您也可以尝试使用单独的属性来提及产品类型(在glassesclothing 之间)。

关于图像大小调整,我找到了一个非常易于使用的脚本,其代码如下:-

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;
}

您肯定需要对要提供的不同尺寸进行一些调整,但这仍然是一段非常好的代码( 可在此处使用),这保存了我的多次回来。

希望有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文