I have a site where I have a lot of product, all the information (and images) is exported from the company accounting system. All images are in the format [productcode].jpg .
In my SS site I import all the product objects directly into the database to make it easy on myself. In the front end I need to link the images to the product data objects....It's working fine, but I need to resize the image as I bring it in. at the moment I've got:
######### in Product.php ############
class Product extends DataObject
{
.............
function FindProductImage() {
$filename = 'assets/product-images/' . $this->ProductCode . '.jpg';
$default_filename = 'themes/allentrading/images/no-product-image.png';
if (Director::fileExists($filename)) {
$findimagepath = $filename;
} else {
$findimagepath = $default_filename;
}
$data = array(
'ProductImagePath' => $smartimagepath
);
return $this->customise($data);
}
In the template I call:
<% control FindProductImage%>
<img src="$ProductImagePath" >
<% end_control %>
The problem is the images are all different sizes so I need to resize them in the template. What I ideally need to do is return the actual image object and then resize it (in the function)...not sure how to do that...or can I somehow do it in the template??
any help appreciated!