Copied to clipboard

Flag this post as spam?

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


  • shanem 39 posts 93 karma points
    Apr 11, 2011 @ 11:25
    shanem
    0

    Umbraco DynamicMedia thumbnail crops

    I can't seem to get the DynamicMedia thumbnail crops genereted via. the Upload data type. I can see all my thumbnails in the media folder but can't access them in the code. Here is my code (Umbraco 4.7):

            public static void GetMediaById(int id)
            {
                dynamic media = new DynamicMedia(id);
    
                var name = media.name;
                var file = media.umbracoFile;
                var ext = media.umbracoExtension;
    
                int width = 0;
                int height = 0;
                try
                {
                    int.TryParse(media.umbracoWidth, out width);
                    int.TryParse(media.umbracoHeight, out height);
                }
                catch
                {
                    // Ignore this as some file types won't have a width or height.
                }
    
                // Get thumbnail crops - how?
    
            }

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 11, 2011 @ 11:35
    Douglas Robar
    0

    When umbraco saves a media file it saves its withd and height and also generates a thumbnail for you (assuming it's an image). The thumbnail has the same filename as the original image, is in the same folder, but has "_thumb" appended to it.

    If the umbracoFile property were "myphoto.jpg" the thumbnail of it would be "myphoto_thumb.jpg"

    Make sense?

    cheers,
    doug.

  • shanem 39 posts 93 karma points
    Apr 11, 2011 @ 12:29
    shanem
    0

    Thank you for the reply. This makes sense. I was hoping the object would have crops so I wouldn't have to hardcode image sizes like this:

    myphoto_thumb60.jpg

    myphoto_thumb111.jpg

    myphoto_thumb482.jpg

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 11, 2011 @ 13:01
    Douglas Robar
    1

    You can make multipel thumbnail sizes automatically with Umbraco (go to the developer section, expand the 'datatypes' section, and click the 'upload' data type... then add a list of sizes such as 60;111;482). Or, use ImageGen which has many more options. There's also the cropper datatype built into umbraco that is very handy.

    But I suspect you mean you want the thumbnail files to be listed in the media object itself but they aren't.

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft