Resize images on the fly
Written by Thomas Kahl   
Friday, 28 May 2010 17:45

Maybe it is an additional feature or just a correct working image-resizer in Virtuemart. But we have also extended it a bit for Virtuemart VMX…

Normally, Virtuemart only uses the image-dimensions you have configured in the Virtuemart configuration. But often the images are needed in different sizes. Now you can do it without problems – and the best thing: the resize script is only called once per image. After the resized image is once created, our improved script recognizes this and directly creates a URL with the image filename. This is slightly better for SEO but it is better for the local cache or most browsers.

How to use it

you might know the image_tag function from some templates. Just add some parameters to resize the images individually for each theme. This is what you can find in a default browse-template:

echo ps_product::image_tag( $product_thumb_image, 'class="browseProductImage" 
border="0" title="'.$product_name.'" alt="'.$product_name .'"' )

This loads and displays the default resized image for the product. Replace it with this:

echo ps_product::image_tag(basename($product_full_image), 'class="browseProductImage" 
border="0" title="'.$product_name.'" 
alt="'.$product_name .'"',1,'product',250,300 )

and you will receive a new thumb-image with the max-dimension of 250x300 rendered from the full image (for better quality). Notice: the function “basename” is needed, because sometimes the image variable holds the full URL of the local image.

This can be used in all themes where you want to display images. A good way for example to show very small thumbs in the cart.

Trackback(0)
Comments (3)Add Comment

Write comment
smaller | bigger

security code
Write the displayed characters


busy
 

Blog Newsletter

Blog RSS-Feed Click here

Subscribe to our Blog Newsletter

Enter your email address:

Delivered by FeedBurner