Generate Image Size via URL parameters#
Description#
Create a new page in Miva called REQUEST_IMAGE with the following code:
Snippet#
<mvt:assign name="l.constraints[1]:height" value="encodeentities(g.image_height)" />
<mvt:assign name="l.constraints[1]:width" value="encodeentities(g.image_width)" />
<mvt:assign name="l.imagetype_codes[1]" value="encodeentities(g.image_type)" />
<mvt:do name="l.success" file="g.Module_Library_DB" value="Product_Load_Code( encodeentities(g.Product_Code), l.settings:product )" />
<mvt:assign name="l.constraints_count" value="miva_array_elements( l.constraints )" />
<mvt:assign name="l.imagetypecode_count" value="miva_array_elements( l.imagetype_codes )" />
<mvt:do file="g.Module_Library_DB" name="l.imagedata_count" value="ProductImageDataList_Load_Product_TypeCodes_Constrained(l.settings:product:id, l.imagetype_codes, l.imagetypecode_count , l.constraints,l.constraints_count,l.settings:productimagedatalist)" />
<mvt:comment>
Check and see if the image size requested exists on the server, If not dynamically create it
</mvt:comment>
<mvt:if expr="ISNULL l.settings:productimagedatalist[1]:generatedimages[1]:image">
<mvt:do file="g.Module_Library_DB" name="l.ok" value="GeneratedImage_FindOrInsert_Image_Dimensions( l.settings:productimagedatalist[1]:image, l.constraints[1]:width, l.constraints[1]:height, l.settings:generatedimage )" />
<mvt:assign name="l.ok" value="file_read( '/' $ g.Domain:mod_root $ l.settings:generatedimage:image, 'script', g.image_data)" />
<mvt:else>
<mvt:assign name="l.ok" value="file_read( '/' $ g.Domain:mod_root $ l.settings:productimagedatalist[1]:generatedimages[1]:image, 'script', g.image_data)" />
</mvt:if>
<mvt:eval expr="g.image_data" />
Add .htacces rewrite rule
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/request_image.jpg$ [NC]
RewriteRule ^(.*)$ http://domain.com/mm5/merchant.mvc?Screen=REQUEST_IMAGE [QSA,L]
Pass Image size, image type and product code in as parameters
<img src="/request_image.jpg?Product_Code=test&image_type=main&image_height=200&image_width=500" border="0" />
Functions Used#
Product_Load_Code
miva_array_elements
ProductImageDataList_Load_Product_TypeCodes_Constrained
GeneratedImage_FindOrInsert_Image_Dimensions