加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何在Magento中的任何图像上使用自适应调整大小?

发布时间:2020-12-13 16:52:23 所属栏目:PHP教程 来源:网络整理
导读:我找到了这个模块,它使用自适应调整大小来生成产品图像. https://github.com/wearefarm/magento-adaptive-resize 现在我想弄清楚,如何在Magento中的任何其他图像上使用自适应调整大小功能? 我尝试这样称呼它,但它不起作用: ?php $imager = $this-getSkinUr
我找到了这个模块,它使用自适应调整大小来生成产品图像. 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);?>

解决方法

没关系,我找到了解决方案.我创建了一个带帮助程序的自定义模块,其中包含来自第三方脚本Zebra Image http://stefangabos.ro/php-libraries/zebra-image/的函数

这是我创建的Helper文件夹中的Data.php文件:

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

我现在可以通过指定图像的路径和目标目录来为任何图像执行任务:Mage :: helper(‘customContent’) – > resize($_ imageUrl,$imageResized);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读