Copy link to clipboard
Copied
I Have a page that displays a series of available items for the public to purchase. each of these items displays an image of the product. My cfimage code is made to scale-to-fit the stored image. normally the displayed results will all shoe different products and their corps pounding images. When I use the code below all of my different products will show the same image instead of showing the images that are linked to each product via a file path stored in the database. Is there a way to set the "name="myImage" dynamically so that each image will display and scale properly?
<cfimage source="C:\ColdFusion9\wwwroot\shotthp\#product.proimage#" name="myImage">
<!--- Turn on antialiasing. --->
<cfset ImageSetAntialiasing(myImage)>
<cfset ImageScaleToFit(myImage,182,"","highestPerformance")>
Copy link to clipboard
Copied
You should set the source attribute dynamically, rather than the name attribute. Get its value, the image path linked to a particular product, from a database query.
Copy link to clipboard
Copied
Thanks for the reply. The image source="C:\ColdFusion9\wwwroot\shotthp\#product.proimage#" is set dynamically. As the #product.proimage# finishes the path to the actual images Which some are in different folders.
The image path is actually "C:\ColdFusion9\wwwroot\shotthp\image\source\hats\caps\photo24.jpg" as is the next image should point to "C:\ColdFusion9\wwwroot\shotthp\image\source\hats\caps\dcs_45.jpg" which normally displays a different image But the page is displaying the same image in each thumbnail.
Copy link to clipboard
Copied
Assuming that 'product' is the name of the query that contains the path of the image of each product, then you could just use cfoutput. I have assumed in the following that each row in the result-set corresponds to a specific product.
<cfoutput query="product">
<!--- In what follows, myImage is the dynamic name for the image corresponding to each row --->
<cfimage source="C:\ColdFusion9\wwwroot\shotthp\#product.proimage#" name="myImage">
<!--- Turn on antialiasing. --->
<cfset ImageSetAntialiasing(myImage)>
<cfset ImageScaleToFit(myImage,182,"","highestPerformance")>
<!--- More code pertaining to each row, hence to each product. For example, create the folder, scaledProductImages, beforehand and store the edited images for later use --->
<cfimage source="#myImage#" action="write" destination="C:\ColdFusion9\wwwroot\shotthp\scaledProductImages\#product.proimage#" overwrite="yes">
</cfoutput>