图像旋转在Magento


Image rotation in Magento

我正试图为供应商上传到我的商店的图像添加旋转功能。我已经添加了一个旋转按钮,您将在下面的html代码中看到它。旋转按钮在上传图像的缩略图上。我有困难与我的php代码。我想让它获取图像数据,旋转并保存。谢谢。

我phtml

:

<article class="item">
        {{if url}}
        <a href="{{:url}}" class="preview lightbox">
        {{else}}
        <a class="preview">
        {{/if}}
            <button class="sort" title="<?php echo $helper->__('Drag to sort') ?>"></button>
            <span class="error-message" data-tooltip='<?php echo json_encode($tooltipError) ?>'><?php echo $helper->__('Error') ?></span>
            <span class="starred" title="<?php echo $helper->__('Default image') ?>" data-tooltip='<?php echo json_encode($tooltipDefault) ?>'></span>
            <button class="remove" title="<?php echo $helper->__('Delete image') ?>"></button>
            <button class="rotate" title="<?php echo $helper->__('Rotate image') ?>"></button>
            <img class="thumbnail" onload="var img = jQuery(this); setTimeout(function () {img.next('.loader').remove();}, 1200);" {{if thumbnailUrl}}src="{{:thumbnailUrl}}"{{else}}href="{{:url}}"{{/if}}/>
            <span class="loader"></span>
        </a>
    </article>

我的php:

public function productRotateImageAction()
{
    $mediaApi = Mage::getModel("catalog/product_attribute_media_api")->getMediaUrl($image['file']);
    $gallery->getBackend()->rotateImage($image->getFile());
    $degrees = 90;
    $source = imagecreatefromjpeg($image);
    $rotate = imagerotate($source, $degrees, 0);
    imagejpeg($rotate);
    imagedestroy($source);
    imagedestroy($rotate);
}

试试这个:http://docs.magentocommerce.com/Varien/Varien_Image/Varien_Image.html尝试使用Varien类来处理图像。