Thumbnails in Blogengine.NET

by James Archuleta

August/12/2009 23:36

After searching the web and being unable to find one that works. I hacked up my own.

I had to change the Add Entry pages, as I was unable to make this happen using the extensions to blogengine.net, ideally there should be a better way to do this, but I was unable to find one.

Here's how I did it.

Add_entry.aspx (7.31 kb)


<asp:CheckBox ID="CheckBoxThumb" runat="server" Text="Generate Thumbnail" Checked="true" />

 

 

Add_entry.aspx.cs (14.10 kb)

if (CheckBoxThumb.Checked)
{
    string thumbPath = Server.MapPath(folder + relativeFolder);
    int width = 250; // you can change the size here
    GenerateThumbnail(thumbPath, fileName, width);
    img = string.Format("<a class="\"lightbox\"" 
        href="\"{0}image.axd?picture={1}\""> 
        <img src="\"{0}image.axd?picture={2}\"" alt="\"\" />", path, 
        Server.UrlEncode(relativeFolder.Replace("\\", "/"") + fileName),    
        Server.UrlEncode(relativeFolder.Replace("\\", "/"") + "thumb_"  
        + fileName));

    txtContent.Text += img;
    txtRawContent.Text += img;
}
else
{
    img = string.Format("&ltimg src="\"{0}image.axd?picture={1}\""
       alt="\"\"" />",
path, Server.UrlEncode(relativeFolder.Replace("
\\", "/") + fileName)); txtContent.Text += img; txtRawContent.Text += img; }
private void GenerateThumbnail(string path, string filename, int width)
{
    using (Image orig = Image.FromFile(path + filename))
    {
        this.GenerateThumbnail(orig, new Size(width, 
               CalculateHeight(orig, width)), 
               GetFormat(filename), path + "thumb_" + filename);            
    }
}

private void GenerateThumbnail( System.Drawing.Image orig, 
                Size size,ImageFormat format, 
                String location)
{
        System.Drawing.Image.GetThumbnailImageAbort callback = new 
System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); System.Drawing.Image img = orig.GetThumbnailImage(size.Width, size.Height, callback, IntPtr.Zero); img.Save(location, format); } private static ImageFormat GetFormat(string filename) { if (filename.EndsWith("jpg") || filename.EndsWith("jpeg") || filename.EndsWith("tiff")) return ImageFormat.Jpeg; return ImageFormat.Png; } private static int CalculateHeight( System.Drawing.Image img, double desiredWidth) { double power = img.Width / desiredWidth; return (int)(img.Height / power); } private bool ThumbnailCallback() { return false; }

The whole thing came out really nice. I also added the Jquery Lightbox plugin. for the images.

Conversion To BlogEngine.Net

by James Archuleta

August/2/2009 19:14

So I've finally moved away from Drupal. It was much nicer in a Linux environment, but now that move to a new host for .Net stuff. It makes sense that I should switch to new CMS system. Also I love working .NET as opposed to PHP.

I've still got a lot go as far as restoring my old Post and getting everything configured correctly.

I think my first project is to make my own theme, something that I never quite got around to doing before.