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.

Catch a Fly - Game

by James Archuleta

April/21/2009 00:02

This is the final project I did for a flash class. Everyone focues on animations and Web pages. I wanted to make a game.  And Sure, it's not that involved of a game. But its a cool project none the less. This is my first flash game.

Try Clicking on the outlets or the cat.

Hold down the 'W' key if you have problems.

More...

Mortgage Calculator

by James Archuleta

January/7/2009 22:03

This is a projects that I originally did in October of 2008 for a Visual Basic class. It turned out really nice so i'm posting it up here.

You can see the working demo here.

Or download the source MortCalc.zip (1.05 mb)