Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Extending XLite\View\Image to get more info about the image file

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 02-18-2016, 09:59 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Extending XLite\View\Image to get more info about the image file

I want to be able to read the dimensions of the image so I can change the CSS class used depending if the image is landscape or portrait format.

I imagine I should extend XLite\View\Image but I can't work out what I need to do.
__________________
Core version: 5.5.xx
Reply With Quote
  #2  
Old 02-18-2016, 11:54 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Extending XLite\View\Image to get more info about the image file

I guess you should update $this->properties['className'] in a way similar to how the addInlineStyle() method sets the margins when centering the image.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 02-19-2016, 12:29 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: Extending XLite\View\Image to get more info about the image file

I'm doing this to add in my own CSS class

Code:
class ProductDetailImageSizes extends \XLite\View\Image { public function getProperties() { $properties = parent::getProperties(); $currentwidth = NEED SOMETHING HERE TO WORK WITH; unset($properties); // remove all settings from the image class // $properties['style'] = 'width: 80%; max-height: 400px; display: inline'; $properties['class'] = 'product-detail-image-landscape'; $this->properties = $properties; return $properties; } }

I've used this elsewhere to add in Styles and Classes successfully.

However I need to somehow find the image dimensions so I can change the class used depending if it's horizontal or vertical.

processImage() looks like it might offer something with
$this->getParam(self::PARAM_IMAGE)
and
$this->properties['width'],

but I'm not sure what to do.
__________________
Core version: 5.5.xx
Reply With Quote
  #4  
Old 02-19-2016, 01:24 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Extending XLite\View\Image to get more info about the image file

You should use something like this:
PHP Code:
/**
 * Image entity.
 *
 * @var \XLite\Model\Base\Image
 */
$image $this->getParam(self::PARAM_IMAGE);

$originalWidht $image->getWidth();
$originalHeight $image->getHeight();

$vertical $originalHeight $originalWidht
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
xgarb (02-19-2016)
  #5  
Old 02-22-2016, 07:14 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: Extending XLite\View\Image to get more info about the image file

This is what I've done. Works for me.. might be something in here that helps others.

In image-regular.tpl, image-zoom-quicklook.tpl and image-zoom.tpl

I'm calling the widget class...
<widget class="\XLite\Module\Client\ClientTheme\View\Produ ctDetailImageSizes" im....

ProductDetailImageSizes.php looks like this:
Code:
namespace XLite\Module\Client\ClientTheme\View; class ProductDetailImageSizes extends \XLite\View\Image { public function getProperties() { $properties = parent::getProperties(); $image = $this->getParam(self::PARAM_IMAGE); $ratio = $image->getWidth() / $image->getHeight(); $cssClassForImage = $ratio > 1 ? 'product-detail-image-h' : 'product-detail-image-v'; // image CSS Class based on image ratio $cssClassForImage = $image->getWidth() < 310 ? 'product-detail-image-legacy' : $cssClassForImage; // image CSS Class for legacy images < 310px unset($properties); $properties['class'] = $cssClassForImage; return $properties; } }

and in my stylesheet:
Code:
.product-detail-image-legacy { max-width: 80%; height: auto; display: inline !important; } .product-detail-image-h { width: 80%; height: auto; display: inline !important; } .product-detail-image-v { width: auto; max-width: 80%; max-height: 400px; display: inline !important; }
__________________
Core version: 5.5.xx
Reply With Quote

The following user thanks xgarb for this useful post:
qualiteam (02-23-2016)
  #6  
Old 02-23-2016, 10:36 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Extending XLite\View\Image to get more info about the image file

Thank you for sharing it with the community!
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #7  
Old 02-26-2016, 03:08 AM
 
xgarb xgarb is online now
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Re: Extending XLite\View\Image to get more info about the image file

My code didn't seem to like when the default image was set so I've re-written the class....

Code:
class ProductDetailImageSizes extends \XLite\View\Image { public function getProperties() { $properties = parent::getProperties(); $cssClassForImage = 'product-detail-image-legacy'; //default $image = $this->getParam(self::PARAM_IMAGE); if (is_object($image)){ $ratio = $image->getWidth() / $image->getHeight(); if ($image->getWidth() > 310) { // not a legacy image $cssClassForImage = $ratio > 1 ? 'product-detail-image-h' : 'product-detail-image-v'; // image CSS Class based on image ratio } } unset($properties); $properties['class'] = $cssClassForImage; return $properties; } }
__________________
Core version: 5.5.xx
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:40 AM.

   

 
X-Cart forums © 2001-2020