本文整理汇总了PHP中Varien_Image::getOriginalWidth方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Image::getOriginalWidth方法的具体用法?PHP Varien_Image::getOriginalWidth怎么用?PHP Varien_Image::getOriginalWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Image
的用法示例。
在下文中一共展示了Varien_Image::getOriginalWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPreview
public function createPreview($name, $pathModule, $id, $width, $height)
{
if (isset($_FILES[$name]['name']) && $_FILES[$name]['name'] != null) {
$path = Mage::getBaseDir('media') . DS . $pathModule . DS;
$imageObj = new Varien_Image($path . '/' . $_FILES[$name]['name']);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(FALSE);
$imageObj->keepFrame(FALSE);
$currentRatio = $imageObj->getOriginalWidth() / $imageObj->getOriginalHeight();
$targetRatio = $width / $height;
if ($targetRatio > $currentRatio) {
$imageObj->resize($width, null);
} else {
$imageObj->resize(null, $height);
}
$diffWidth = $imageObj->getOriginalWidth() - $width;
$diffHeight = $imageObj->getOriginalHeight() - $height;
//$imageObj->resize($width, $height);
$imageObj->crop(floor($diffHeight * 0.5), floor($diffWidth / 2), ceil($diffWidth / 2), ceil($diffHeight * 0.5));
if (empty($id)) {
$id = Mage::getModel('evoqueflex/evoqueflex')->getCollection()->addOrder('slide_id', 'ASC')->getLastItem()->toArray();
$id = $id['slide_id'];
}
$userfile_extn = explode(".", strtolower($_FILES[$name]['name']));
$imageObj->save($path . 'preview_' . $id . '.' . $userfile_extn[1]);
}
}
示例2: postAction
public function postAction()
{
if (!empty($_FILES)) {
$type = 'file';
if (isset($_FILES[$type]['name']) && $_FILES[$type]['name'] != '') {
try {
$uploadsDir = Mage::getBaseDir('upload');
$uploader = new Varien_File_Uploader($type);
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$path = Mage::getBaseDir('media') . DS . 'upload';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$uploader->save($path, $_FILES[$type]['name']);
$filename = $uploader->getUploadedFileName();
$md5 = md5($filename);
$owner = Mage::getSingleton('customer/session')->getCustomerId() ? Mage::getSingleton('customer/session')->getCustomerId() : Mage::getSingleton('customer/session')->getSessionId();
Mage::getModel('xxx_catalog/upload')->setMd5($md5)->setFilename($filename)->setOwner($owner)->save();
$varienImage = new Varien_Image($uploadsDir . $filename);
$width = $varienImage->getOriginalWidth();
$height = $varienImage->getOriginalHeight();
$data = ['id' => $md5, 'width' => $width, 'height' => $height];
echo json_encode($data);
die;
} catch (Exception $e) {
Mage::log($e->getMessage(), null, $this->_logFile);
echo json_encode(['error' => $this->__($e->getMessage())]);
}
}
}
$this->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
}
示例3: getShortImageSize
public function getShortImageSize($item)
{
$width_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_width');
$height_max = Mage::getStoreConfig('clnews/news/shortdescr_image_max_height');
if (Mage::getStoreConfig('clnews/news/resize_to_max') == 1) {
$width = $width_max;
$height = $height_max;
} else {
$imageObj = new Varien_Image(Mage::getBaseDir('media') . DS . $item->getImageShortContent());
$original_width = $imageObj->getOriginalWidth();
$original_height = $imageObj->getOriginalHeight();
if ($original_width > $width_max) {
$width = $width_max;
} else {
$width = $original_width;
}
if ($original_height > $height_max) {
$height = $height_max;
} else {
$height = $original_height;
}
}
if ($item->getShortWidthResize()) {
$width = $item->getShortWidthResize();
} else {
$width;
}
if ($item->getShortHeightResize()) {
$height = $item->getShortHeightResize();
} else {
$height;
}
return array('width' => $width, 'height' => $height);
}
示例4: getPopupActive
public function getPopupActive()
{
$preview = $this->getRequest()->getParam('popup');
$popupID = $this->getRequest()->getParam('popupid');
if ($preview == "preview" && !empty($popupID)) {
$arrPopup = Mage::getModel('popup/popup')->getPopupPreview($popupID);
} else {
$arrPopup = Mage::getModel('popup/popup')->getPopupActive();
}
if (!empty($arrPopup)) {
// If there is a link, process template tag
if (!empty($arrPopup["popup_url"])) {
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$arrPopup["popup_url"] = $processor->filter($arrPopup["popup_url"]);
}
// If there is a content, process template tag
if (!empty($arrPopup["popup_content_html"])) {
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$arrPopup["popup_content_html"] = $processor->filter($arrPopup["popup_content_html"]);
}
$popupID = $arrPopup["popup_id"];
$storeID = Mage::app()->getStore()->getId();
//Check Cookie
$cookiePopup = Mage::getSingleton('core/cookie')->get('cookie_popup_' . $storeID);
// If there's any cookie or new promo or preview mode
if (!$cookiePopup || $cookiePopup != $popupID || $this->getRequest()->getParam('popup') == 'preview') {
if (!$this->getRequest()->getParam('popup')) {
Mage::getSingleton('core/cookie')->set('cookie_popup_' . $storeID, $popupID, 3600 * 24 * 7);
}
if (!empty($arrPopup["popup_image"])) {
$pathImage = Mage::getBaseDir('media') . "/popup/" . $arrPopup["popup_image"];
if (file_exists($pathImage)) {
$imageObj = new Varien_Image($pathImage);
$arrPopup['popup_image_width'] = $imageObj->getOriginalWidth();
$arrPopup['popup_image_height'] = $imageObj->getOriginalHeight();
}
}
return $arrPopup;
}
} else {
return false;
}
}
示例5: _getResizedImage
protected function _getResizedImage($file, $width, $height, $resizeMode = 'cover')
{
if (empty($file)) {
return false;
}
$width = (int) $width;
$height = (int) $height;
$imagePath = $this->getImageFullPath($file);
$imageFileResized = $width . '_' . $height . '_' . $resizeMode . DS . $file;
$imageFileResizedFullPath = $this->getImageCacheFullPath($imageFileResized);
if (!file_exists($imageFileResizedFullPath) && file_exists($imagePath) || file_exists($imagePath) && filemtime($imagePath) > filemtime($imageFileResizedFullPath)) {
$finalAspectRatio = $width / $height;
$imageObj = new Varien_Image($imagePath);
$imageObj->backgroundColor(array(255, 255, 255));
$originalWidth = (int) $imageObj->getOriginalWidth();
$originalHeight = (int) $imageObj->getOriginalHeight();
$originalAspectRatio = $originalWidth / $originalHeight;
if ($resizeMode == 'cover') {
if ($originalAspectRatio > $finalAspectRatio) {
$cropWidth = $finalAspectRatio * $originalHeight;
$widthDiff = $originalWidth - $cropWidth;
$cropX = (int) ($widthDiff / 2);
$imageObj->crop(0, $cropX, $cropX, 0);
} else {
$cropHeight = (int) ($originalWidth / $finalAspectRatio);
$heightDiff = $originalHeight - $cropHeight;
$cropY = (int) ($heightDiff / 2);
$imageObj->crop($cropY, 0, 0, $cropY);
}
} else {
$imageObj->constrainOnly(false);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
}
$imageObj->resize($width, $height);
$imageObj->quality(100);
$imageObj->save($imageFileResizedFullPath);
}
$imageCacheUrl = $this->getImageCacheUrl($imageFileResized);
if (file_exists($imageFileResizedFullPath)) {
return $imageCacheUrl;
}
return false;
}
示例6: getImageSize
public function getImageSize($image = null, $_maxW = 125, $_maxH = 125, $fix = false)
{
$_baseSrc = Mage::getSingleton('igallery/config')->getBaseMediaPath();
if (file_exists($_baseSrc . $image->getFile())) {
$_imageObject = new Varien_Image($_baseSrc . $image->getFile());
$_sizeArray = array($_imageObject->getOriginalWidth(), $_imageObject->getOriginalHeight());
$_defaultW = $_maxW;
$_defaultH = $_maxH;
if ($_sizeArray[0] / $_sizeArray[1] > $_defaultW / $_defaultH) {
$_defaultW *= floatval($_sizeArray[0] / $_sizeArray[1]) / floatval($_defaultW / $_defaultH);
} else {
$_defaultH *= floatval($_defaultW / $_defaultH) / floatval($_sizeArray[0] / $_sizeArray[1]);
}
if ($fix == 'width') {
if ($_defaultW > $_maxW) {
$_defaultH *= $_maxW / $_defaultW;
$_defaultW = $_maxW;
}
} elseif ($fix == 'height') {
if ($_defaultH > $_maxH) {
$_defaultW *= $_maxH / $_defaultH;
$_defaultH = $_maxH;
}
} else {
if ($_defaultW > $_maxW) {
$_defaultH *= $_maxW / $_defaultW;
$_defaultW = $_maxW;
} elseif ($_defaultH > $_maxH) {
$_defaultW *= $_maxH / $_defaultH;
$_defaultH = $_maxH;
}
}
return new Varien_Object(array('width' => round($_defaultW), 'height' => round($_defaultH)));
}
return false;
}
示例7: saveAction
/**
* save item action
*/
public function saveAction()
{
if (!Mage::helper('magenotification')->checkLicenseKeyAdminController($this)) {
return;
}
if ($data = $this->getRequest()->getPost()) {
if ($sourceFile = $this->_uploadAffiliateBannerFile('source_file')) {
$data['source_file'] = $sourceFile;
}
// Peel large file uploading
if ($peelImage = $this->_uploadAffiliateBannerFile('peel_image')) {
$data['peel_image'] = $peelImage;
}
$bannerId = $this->getRequest()->getParam('id');
$storeId = $this->getRequest()->getParam('store');
$banner = Mage::getModel('affiliateplus/banner');
$banner->setStoreId($storeId)->load($bannerId)->addData($data)->setId($bannerId);
// Prepare image size
if (($sourceFile = $banner->getSourceFile()) && $banner->getTypeId() != Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_FLASH && (!$banner->getWidth() || !$banner->getHeight())) {
try {
$image = new Varien_Image(Mage::getBaseDir('media') . DS . 'affiliateplus' . DS . 'banner' . DS . $sourceFile);
if (!$banner->getWidth()) {
$banner->setWidth($image->getOriginalWidth());
}
if (!$banner->getHeight()) {
$banner->setHeight($image->getOriginalHeight());
}
} catch (Exception $e) {
Mage::logException($e);
}
}
// Prepare image size for Peel banner
if (($sourceFile = $banner->getPeelImage()) && $banner->getTypeId() == Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_PEEL && (!$banner->getPeelWidth() || !$banner->getPeelHeight())) {
try {
$image = new Varien_Image(Mage::getBaseDir('media') . DS . 'affiliateplus' . DS . 'banner' . DS . $sourceFile);
if (!$banner->getPeelWidth()) {
$banner->setPeelWidth($image->getOriginalWidth());
}
if (!$banner->getPeelHeight()) {
$banner->setPeelHeight($image->getOriginalHeight());
}
} catch (Exception $e) {
Mage::logException($e);
}
}
// Try to save banner
try {
$banner->save();
if ($banner->getTypeId() == Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_ROTATOR && isset($data['banners'])) {
$childBanners = array();
if ($banner->getData('banners')) {
parse_str($banner->getData('banners'), $childBanners);
}
Mage::getSingleton('affiliateplusbanner/rotator')->setData('parent_id', $banner->getId())->saveChildBanner($childBanners);
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('affiliateplusbanner')->__('Banner was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $banner->getId(), 'store' => $storeId));
return;
}
$this->_redirect('*/*/', array('store' => $storeId));
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'), 'store' => $storeId));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('affiliateplusbanner')->__('Unable to find banner to save'));
$this->_redirect('*/*/', array('store' => $storeId));
}
示例8: init
public function init($object, $field)
{
if ($field) {
$this->setField($field);
}
$image = $object->getData($this->field);
if (!$image) {
return false;
}
$this->getMedia();
// set media
$Url = $this->getPath($object);
$img = explode('/', $image);
$img = end($img);
$Url['original'] .= $img;
$Url['resized'] .= $img;
if (!is_file($Url['original'])) {
return false;
}
if (file_exists($Url['resized'])) {
$imageResizedObj = new Varien_Image($Url['resized']);
if ($this->width != $imageResizedObj->getOriginalWidth() || $this->height != $imageResizedObj->getOriginalHeight() || filemtime($Url['original']) > filemtime($Url['resized'])) {
$this->convertImage($Url['original'], $Url['resized']);
}
} else {
if (file_exists($Url['original'])) {
$this->convertImage($Url['original'], $Url['resized']);
}
}
if (file_exists($Url['resized'])) {
$Url['url_resized'] .= $img;
return $Url['url_resized'];
} else {
$Url['url_original'] .= $img;
return $Url['url_original'];
}
}
示例9: renderImageAttributes
public function renderImageAttributes($relativeUrl, $width = null, $height = null)
{
if ($filename = $this->getFilename($relativeUrl, 'image')) {
if ($width || $height) {
$processor = new Varien_Image($filename);
$newRelativeUrl = 'w' . ($width ? $width : 'x') . 'h' . ($height ? $height : 'x') . '/' . $relativeUrl;
if (!$width) {
$width = $processor->getOriginalWidth();
}
if (!$height) {
$height = $processor->getOriginalHeight();
}
$processor->keepAspectRatio(true);
$processor->resize($width, $height);
$processor->save($this->getFilename($newRelativeUrl, 'image', true));
return "src=\"{$this->getUrl($newRelativeUrl, 'image')}\" " . "width=\"{$processor->getOriginalWidth()}\" " . "height=\"{$processor->getOriginalHeight()}\"";
} else {
return "src=\"{$this->getUrl($relativeUrl, 'image')}\"";
}
}
}
示例10: getImageSize
public function getImageSize($image = null, $w, $h, $fix = false)
{
if (file_exists($image->getPath())) {
try {
$i = new Varien_Image($image->getPath());
$s = array($i->getOriginalWidth(), $i->getOriginalHeight());
$_defaultW = $w;
$_defaultH = $h;
if ($s[0] / $s[1] > $_defaultW / $_defaultH) {
$_defaultW *= floatval($s[0] / $s[1]) / floatval($_defaultW / $_defaultH);
} else {
$_defaultH *= floatval($_defaultW / $_defaultH) / floatval($s[0] / $s[1]);
}
if ($fix == 'width') {
if ($_defaultW > $w) {
$_defaultH *= $w / $_defaultW;
$_defaultW = $w;
}
} elseif ($fix == 'height') {
if ($_defaultH > $h) {
$_defaultW *= $h / $_defaultH;
$_defaultH = $h;
}
} else {
if ($_defaultW > $w) {
$_defaultH *= $w / $_defaultW;
$_defaultW = $w;
} elseif ($_defaultH > $h) {
$_defaultW *= $h / $_defaultH;
$_defaultH = $h;
}
}
return new Varien_Object(array('width' => round($_defaultW), 'height' => round($_defaultH)));
} catch (Exception $e) {
}
}
return new Varien_Object(array('width' => round($w), 'height' => round($h)));
}
示例11: handleUpload
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
function handleUpload($uploadDirectory, $slider_dimensions, $replaceOldFile = FALSE)
{
if (!is_writable($uploadDirectory)) {
return array('error' => Mage::helper('lookbookslider')->__("File can't be uploaded. Upload directory isn't writable."));
}
if (!$this->filemodel) {
return array('error' => Mage::helper('lookbookslider')->__("Uploader error. File was not uploaded."));
}
$size = $this->filemodel->getSize();
if ($size == 0) {
return array('error' => Mage::helper('lookbookslider')->__("File is empty"));
}
if ($size > $this->sizeLimit) {
return array('error' => Mage::helper('lookbookslider')->__("File is too large"));
}
$pathinfo = pathinfo($this->filemodel->getName());
$filename = $pathinfo['filename'];
//$filename = md5(uniqid());
$filename = uniqid();
$ext = $pathinfo['extension'];
if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
$these = implode(', ', $this->allowedExtensions);
return array('error' => Mage::helper('lookbookslider')->__("File can't be uploaded. It has an invalid extension, it should be one of %s.", $these));
}
if (!$replaceOldFile) {
/// don't overwrite previous files that were uploaded
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
}
if ($this->filemodel->save($uploadDirectory . $filename . '.' . $ext)) {
$imgPathFull = $uploadDirectory . $filename . '.' . $ext;
$image_dimensions = Mage::helper('lookbookslider')->getImageDimensions($imgPathFull);
if (!isset($image_dimensions['error'])) {
/////////////////////////////////////////////
$resized_image = new Varien_Image($imgPathFull);
$resized_image->constrainOnly(FALSE);
$resized_image->keepAspectRatio(TRUE);
$resized_image->keepTransparency(TRUE);
$resized_image->keepFrame(FALSE);
if ($slider_dimensions['width'] / $slider_dimensions['height'] > $resized_image->getOriginalWidth() / $resized_image->getOriginalHeight()) {
$resized_image->resize($slider_dimensions['width'], null);
} else {
$resized_image->resize(null, $slider_dimensions['height']);
}
$cropX = 0;
$cropY = 0;
if ($resized_image->getOriginalWidth() > $slider_dimensions['width']) {
$cropX = intval(($resized_image->getOriginalWidth() - $slider_dimensions['width']) / 2);
} elseif ($resized_image->getOriginalHeight() > $slider_dimensions['height']) {
$cropY = intval(($resized_image->getOriginalHeight() - $slider_dimensions['height']) / 2);
}
$resized_image->crop($cropY, $cropX, $cropX, $cropY);
$resized_image->save($imgPathFull);
$image_dimensions = Mage::helper('lookbookslider')->getImageDimensions($imgPathFull);
/////////////////////////////////////////////
} else {
return array('error' => Mage::helper('lookbookslider')->__("Could not get uploaded image dimensions."));
}
return array('success' => true, 'filename' => $filename . '.' . $ext, 'dimensions' => $image_dimensions);
} else {
return array('error' => Mage::helper('lookbookslider')->__("Could not save uploaded file. The upload was cancelled, or server error encountered"));
}
}
示例12: getCustomSizeImageUrl
/**
* Retrieve custom size image url
*
*
* @param string $imageUrl
* @param int $width
* @param int $height
* @return string|null
*/
public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
{
$screenSize = $width . 'x' . $height;
$customDir = $this->getMediaPath('custom' . DS . $screenSize);
$this->_verifyDirExist($customDir);
$imageUrl = explode('/', $imageUrl);
$file = array_pop($imageUrl);
$filePath = Mage_XmlConnect_Model_Images::getBasePath() . DS . $file;
if (!file_exists($customDir . DS . $file)) {
$image = new Varien_Image($filePath);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(255, 255, 255));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($file));
}
}
return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
}
示例13: getCustomSizeImageUrl
/**
* Retrieve custom size image url
*
* @param string $imageFile
* @param int $width
* @param int $height
* @return string|bool
*/
public function getCustomSizeImageUrl($imageFile, $width = 100, $height = 100)
{
/** @var $imageHelper Mage_XmlConnect_Helper_Image */
$imageHelper = Mage::helper('xmlconnect/image');
$screenSize = $width . 'x' . $height;
$customDir = $imageHelper->getMediaPath('custom' . DS . $screenSize);
$ioFile = new Varien_Io_File();
$ioFile->checkAndCreateFolder($customDir);
$filePath = self::getBasePath() . DS . $imageFile;
$isImagePng = true;
if (!$ioFile->fileExists($filePath)) {
return false;
}
$originalImageType = $this->_getImageType($filePath);
if ($originalImageType !== IMAGETYPE_PNG) {
$imageFile = $this->_convertFileExtensionToPng($imageFile);
$isImagePng = false;
}
$customSizeFile = $customDir . DS . $imageFile;
if (!file_exists($customSizeFile)) {
if (!$isImagePng) {
$filePath = $this->_forcedConvertPng($filePath, $customSizeFile, $originalImageType);
}
$image = new Varien_Image($filePath);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(0, 0, 0));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($imageFile));
} else {
$ioFile->cp($filePath, $customSizeFile);
}
}
return $imageHelper->getMediaUrl("custom/{$screenSize}/" . basename($imageFile));
}
示例14: _renderCategoryMenuItemHtml
//.........这里部分代码省略.........
}
$gan_plain_style = ($this->_navigation_place == self::MENU_BAR ? 'background-color: ' . $this->getColumnColor() . ';' : '') . ($_width ? 'width: ' . $_width . 'px;' : '');
if ($gan_plain_style) {
$gan_plain_style = 'style="' . $gan_plain_style . '"';
}
$html[] = '<div ' . $gan_plain_style . ' class="gan-plain" >';
if (!($this->_navigation_place == self::MENU_BAR)) {
$html[] = '<span class="gan-plain-border"></span>';
}
$_add_style = '';
if ($this->_navigation_place == self::MENU_BAR) {
$navigation_image = $category->getData('navigation_image');
$navigation_image_position = $category->getData('navigation_image_position');
if ($navigation_image) {
$navigation_image = $this->getResizedImage($navigation_image, $category->getData('navigation_image_width'), $category->getData('navigation_image_height'));
}
if ($navigation_image) {
$_add_image_style = '';
if ($category->getData('navigation_image_width')) {
$_add_image_style = 'width:' . $category->getData('navigation_image_width') . 'px;';
}
if ($category->getData('navigation_image_height')) {
$_add_image_style .= 'height:' . $category->getData('navigation_image_height') . 'px;';
}
if ($_add_image_style) {
$_add_image_style = 'style="' . $_add_image_style . '"';
}
$this->_plain_image = '<div class="' . GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::getPositionClass($navigation_image_position) . '">';
$this->_plain_image .= '<img ' . $_add_image_style . ' src="' . Mage::getBaseUrl('media') . "catalog/product/cache/cat_resized/" . $navigation_image . '" alt="' . $this->escapeHtml($category->getName()) . '" />';
$this->_plain_image .= '</div>';
$imageObj = new Varien_Image(Mage::getBaseDir('media') . DS . "catalog" . DS . "product" . DS . "cache" . DS . "cat_resized" . DS . $navigation_image);
switch ($navigation_image_position) {
case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::RIGHT:
$_add_style = ' style="margin-right: ' . ((int) ($category->getData('navigation_image_width') ? $category->getData('navigation_image_width') : $imageObj->getOriginalWidth()) + 10) . 'px;" ';
$html[] = $this->_plain_image;
$this->_plain_image = '';
break;
case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::TOP:
$html[] = $this->_plain_image;
$this->_plain_image = '';
break;
case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::BOTTOM:
break;
default:
case GoMage_Navigation_Model_Adminhtml_System_Config_Source_Category_Image_Position::LEFT:
$_add_style = ' style="margin-left: ' . ((int) ($category->getData('navigation_image_width') ? $category->getData('navigation_image_width') : $imageObj->getOriginalWidth()) + 10) . 'px;" ';
$html[] = $this->_plain_image;
$this->_plain_image = '';
break;
}
}
}
$html[] = '<div ' . $_add_style . ' class="gan-plain-items">';
$activeChildren = $this->sort_category($activeChildren);
}
} else {
$_cat_column = null;
if ($category->getLevel() == $this->_root_level + 1) {
if ($this->_navigation_place == self::MENU_BAR) {
$_cat_column = $category->getData('navigation_column') ? $category->getData('navigation_column') : 1;
} else {
$_cat_column = $category->getData('navigation_column_side') ? $category->getData('navigation_column_side') : 1;
}
}
if ($this->_childs_count == 1 || $_cat_column && $_cat_column != $this->_current_column) {
$this->_current_column = $_cat_column;
示例15: getCustomSizeImageUrl
/**
* Retrieve thumbnail image url
*
* @param string $imageUrl
* @param int $width
* @param int $height
* @return string|null
*/
public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
{
$screenSize = $width . 'x' . $height;
$customDir = $this->getMediaPath('custom' . DS . $screenSize);
$this->_verifyDirExist($customDir);
$imageUrl = explode('/', $imageUrl);
$file = $imageUrl[count($imageUrl) - 1];
$filePath = $this->getDefaultSizeUploadDir() . DS . $file;
if (!file_exists($customDir . DS . $file)) {
$adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType();
$image = new Varien_Image($filePath, $adapter);
$widthOriginal = $image->getOriginalWidth();
$heightOriginal = $image->getOriginalHeight();
if ($width != $widthOriginal) {
$widthOriginal = $width;
}
if ($height != $heightOriginal) {
$heightOriginal = $height;
}
if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) {
$image->keepTransparency(true);
$image->keepFrame(true);
$image->keepAspectRatio(true);
$image->backgroundColor(array(255, 255, 255));
$image->resize($widthOriginal, $heightOriginal);
$image->save($customDir, basename($file));
}
}
return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
}