The {random} keyword will select an image from a folder at random. But of course you'd need to have a variety of images in the folder to choose from for {random} to work. Otherwise you'd always get the same thing, which is almost certainly what is happening for you because Umbraco typically puts only a single image in each media folder item. Thus, imagegen.ashx?image=/media/2124223/{random}&width=94 would likely always produce the same output.
On the other hand, if you have a folder that users upload their latest holiday snaps to (rather than using the media section of Umbraco), then using imagegen.ashx?image=/snaps/our_holiday/{random}&width=94 should work nicely.
Random image syntax
I am trying to return a random image from folder using ImageGen, but am having trouble finding the correct syntax.
In page 16 of the Reference Manual it says to use something like this to get a random image:
/images/{random}
This is how I currently return an image in a Razor view://mydomain.com/ImageGen.ashx?image=/media/2124223/myimage.jpg&width=994
I've tried putting "{random}" in various spots of the url with no luck. Any tips or guidance would be appreciated, thanks!
Hi, Victor,
The {random} keyword will select an image from a folder at random. But of course you'd need to have a variety of images in the folder to choose from for {random} to work. Otherwise you'd always get the same thing, which is almost certainly what is happening for you because Umbraco typically puts only a single image in each media folder item. Thus, imagegen.ashx?image=/media/2124223/{random}&width=94 would likely always produce the same output.
On the other hand, if you have a folder that users upload their latest holiday snaps to (rather than using the media section of Umbraco), then using imagegen.ashx?image=/snaps/our_holiday/{random}&width=94 should work nicely.
cheers,
doug.
is working on a reply...