上传时的magento图像裁剪

时间:2013-09-17 07:08:56

标签: magento magento-1.7

在我的Magento项目中,我自定义了博客扩展,并为每个帖子添加了图片上传器。图像字段使用“图像”作为字段类型。在控制器中,我使用继承Varien_File_Uploader_Image的{​​{1}}类来实例化上传器。但显然这两个文件中的代码是错误的,Varien_File_Uploader的构造函数是错误的,crop()方法也不起作用。我想知道我可以在Magento中使用现有的功能来进行裁剪吗?我知道产品图片,有生成缩略图的功能,但我不知道那段代码在哪里。

干杯!

1 个答案:

答案 0 :(得分:2)

您可以使用Varien_Image类在自定义模块中添加裁剪功能

$path = Mage::getBaseDir('media') . DS .'your_folder'. DS;
imname = 'yourimagename.jpg';

$img_location = $path.$imbfname;
$image= new Varien_Image($img_location);
$image->crop($top, $left, $right, $bottom)
$image->save($img_location);

希望这对您有所帮助。