Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Aug 07, 2011 @ 11:25
    Niklas Hjelm
    0

    How to get media thumbnail?

    Hi 

    I'm using this script to get media items. There is an XSLT example with som regex where you insert "_thumb" before jpg. Does anyone know how to do that using razor in the example code below?

    Thanks / Niklas


    @foreach(dynamic d in Model.kollektion.mediaItem)
        {
         
          if (d.BaseElement.Name == "Image")
          {
            <img src="@d.umbracoFile" alt="@d.nodeName" />
          }
          else
          {
            <img src="@d.Image.umbracoFile" alt="@d.Image.nodeName" />
          }
        }

  • Jesper Hauge 298 posts 487 karma points c-trib
    Aug 08, 2011 @ 10:10
    Jesper Hauge
    1

    Hi Niklas

    You could probably do it with a string operation like:

    ((string)d.umbracoFile).Replace(".jpg", "_thumb.jpg")

    But instead I'd recommend you use Douglas Robars excellent ImageGen package. With that installed you can generate thumbnails in any size you wish like this:

    <img src="/umbraco/imagegen.ashx?width=100&height=100&[email protected]" />

    Check out Douglas's documentation for further info, it's on the project page.

    Regards
    Jesper 

  • Idan 3 posts 23 karma points
    Dec 26, 2012 @ 19:43
    Idan
    0

    thanks Jesper , works like a magic !

  • André Steenbergen 23 posts 43 karma points
    Apr 18, 2015 @ 12:42
    André Steenbergen
    0

    I know this is an old thread, but it helped me out. But I would recommend:

    <img src="@(Regex.Replace(img.Url, "\\.(.*?)$", "_thumb.$1"))" />

    As a png could be uploaded as well.

  • LeszekP 27 posts 78 karma points
    Jul 03, 2015 @ 11:44
    LeszekP
    0

    Hi,

    Is it working for you? As I see Umbraco creates thumbs with jpg extension, even if the source is PNG.

    Second. For small image files like 5kb Umbraco did NOT create thumb file.

Please Sign in or register to post replies

Write your reply to:

Draft