如何在Magento上使用自适应缩放调整任何图像?

4
我找到了一个模块,可以在产品图片中使用自适应调整大小。 https://github.com/wearefarm/magento-adaptive-resize 现在我正在尝试弄清楚如何在Magento的其他图像上使用该自适应调整大小功能? 我尝试这样调用它,但它没有起作用:
<?php $imager = $this->getSkinUrl('images/thumb_image/something-something.jpg');
$imager = Mage::helper('catalog/image')->AdaptiveResize(100,200);?>
1个回答

3

没事了,我找到了解决办法。我创建了一个带有 helper 的自定义模块,其中包含来自第三方脚本 Zebra Image 的函数http://stefangabos.ro/php-libraries/zebra-image/

Here's the Data.php file in the Helper folder, that I created:

class yokubo_customContent_Helper_Data extends Mage_Core_Helper_Abstract{

    public function resize($img,$target) {
     $ExternalLibPath=Mage::getModuleDir('lib', 'yokubo_customContent'). DS . 'lib' . DS .'Zebra_Image.php';
     require_once ($ExternalLibPath);
     $image = new Zebra_Image();
     $image->source_path = $img;
     $image->target_path = $target; 
     $image->jpeg_quality = 100;
     $image->preserve_aspect_ratio = true;
     $image->enlarge_smaller_images = true;
     $image->preserve_time = true;
     $image->resize(300, 300, ZEBRA_IMAGE_CROP_CENTER);
}

And I can now excute it anywhere for any image, by specifing the path and the target directory for the image: Mage::helper('customContent')->resize($_imageUrl,$imageResized);


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接