0
我想爲供應商上傳到我的商店的圖像添加旋轉功能。我添加了一個旋轉按鈕,您將在下面的我的phtml代碼中看到。旋轉按鈕位於上傳圖像的縮略圖上。我的PHP代碼有問題。我想讓它獲取圖像數據,旋轉並保存。謝謝。Magento中的圖像旋轉
我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);
}
所以這樣? '代碼 公共函數productRotateImageAction() { /** @var Mage_Catalog_Model_Product_Attribute_Media_Api $ mediaApi */$ = mediaApi法師:: getModel( 「product_attribute_media_api」); $ image = new Varien_Image($ mediaApi); $ image-> rotate(90); }' –
$ image = new Varien_Image($ filePath); $圖像 - >旋轉(90); –
$ image-> save($ newPath); –