Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Victor Foster 8 posts 69 karma points
    Feb 14, 2013 @ 23:20
    Victor Foster
    0

    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!



     

  • Douglas Robar 3563 posts 4597 karma points MVP 6x admin c-trib
    Feb 15, 2013 @ 02:30
    Douglas Robar
    100

    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. 

Please Sign in or register to post replies

Write your reply to:

Draft