Copied to clipboard

Flag this post as spam?

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


  • Meni 271 posts 507 karma points
    Apr 30, 2013 @ 17:58
    Meni
    0

    Is it possible to create a Thumbnail using Razor? (Without ImageGen)

    Hello,

    So my first Umbraco site is almost done, and actually I'm struggeling now with the thumbnails issue. 

    The point it that I don't want to use the ImageGen because I don't want to install packages, etc. 

    So I tried using the WebImage - like here - but it's not work. I tried to put the code here into script (Developer - Scripting - New) and it's just not show nothing nor thumbnail..

    http://www.asp.net/web-pages/tutorials/files,-images,-and-media/9-working-with-images

    This the code from the page I tried (w/o success ...):

    @{  
        WebImage photo = null;
        var newFileName = "";
        var imagePath = "";
        var imageThumbPath  = "";
    
        if(IsPost){
            photo = WebImage.GetImageFromRequest();
            if(photo != null){
                 newFileName = Guid.NewGuid().ToString() + "_" +
                     Path.GetFileName(photo.FileName);
                 imagePath = @"media\" + newFileName;
                 photo.Save(@"~\" + imagePath);
    
                imageThumbPath = @"media\thumbs\" + newFileName;
                photo.Resize(width: 60, height: 60, preserveAspectRatio: true,
                   preventEnlarge: true);
                photo.Save(@"~\" + imageThumbPath);        }
        }
    

    }

    So actually, one of the answers I got here was to use the Upload which generate Thumbnails instead of the Media picker. 

    I'm confused already - because in most of the posts gere and the tutorials I see that it's not reccomend as well as if I use the upload property - so how can I handle the image I'm upload? As well as - where it upload it to? 

    So, how do I do it? Any solution? thanks. 

Please Sign in or register to post replies

Write your reply to:

Draft