BlogEngine.NET CoffeeHouse theme released!

Posted on October 30, 2007 00:29 by Michael

Back in July I submitted two themes to be included in the popular open source blogging platform BlogEngine.NET (which I use for this blog). One of those themes, GirlGeek (which was a generic version of my wife's family blog), was included in the release but the second theme, CoffeeHouse, was understandably passed on due to it's similarity to GirlGeek and the Dirtylicious theme for which my two themes were loosely based.

After a number of emails from BlogEngine.NET users asking for a copy of the CoffeeHouse theme I have finally gotten around to tidying up the source code and updating it for BlogEngine.NET v1.2 and I can therefore now make it available for download!

Hopfully I will also be able to contribute an original theme or two to the BlogEngine.NET community in the not too distant future?! But for now I hope you find CoffeeHouse useful.

CoffeeHouse1_2.zip (41.64 kb)

Update: I have updated the zip file above as it wrongly contained a published version of the theme folder instead of the original source (the site.master.cs file was missing and the site.master had an incorrect inheritance reference).

More...

Crop and resize an image in ASP.NET

Posted on August 20, 2007 23:57 by Michael

I have just spent some time implementing a database stored central image library into a web application and this library will be utilised where the application's various content requires associated images.

The main database table for storing the binary image data (and metadata) has multiple binary columns to store different sizes of the image, in a similar vein to photosharing sites like Flickr, where the sizes are as follows: thumbnail, small, medium, large and the original image. In addition to these sizes I wanted to store a square 75x75 pixel representation of the image which would be appropriately cropped. After spending several hours playing with the System.Drawing namespaces and still scratching my head somewhat, I went back to google to try and find some samples (my initial searches didn't find much?!) and eventually came across a good article on The Code Project site which includes a great method which resizes and crops the supplied image.

Here is an example of the code I used which is very useful to have in your code snippets library!... 

protected static System.Drawing.Image ImageCrop(
    System.Drawing.Image imgPhoto, int Width, int Height,
    AnchorPosition Anchor)
{

    int sourceWidth = imgPhoto.Width;
    int sourceHeight = imgPhoto.Height;
    int sourceX = 0;
    int sourceY = 0;
    int destX = 0;
    int destY = 0;

    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;

    nPercentW = ((float)Width / (float)sourceWidth);
    nPercentH = ((float)Height / (float)sourceHeight);

    if (nPercentH < nPercentW)
    {
        nPercent = nPercentW;
        switch (Anchor)
        {
            case AnchorPosition.Top:
                destY = 0;
                break;
            case AnchorPosition.Bottom:
                destY = (int)(Height - (sourceHeight * nPercent));
                break;
            default:
                destY = (int)((Height - (sourceHeight * nPercent)) / 2);
                break;
        }
    }
    else
   
{
        nPercent = nPercentH;
        switch (Anchor)
        {
            case AnchorPosition.Left:
               
destX = 0;
                break;
            case AnchorPosition.Right:
                destX = (int)(Width - (sourceWidth * nPercent));
                break;
            default:
                destX = (int)((Width - (sourceWidth * nPercent)) / 2);
                break;
        }

   

    int destWidth = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent); 

    Bitmap bmPhoto = new Bitmap(Width, Height,
       
PixelFormat.Format24bppRgb);
    bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
        imgPhoto.VerticalResolution);

    Graphics grPhoto = Graphics.FromImage(bmPhoto);
    grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;

    grPhoto.DrawImage(imgPhoto,
        new Rectangle(destX, destY, destWidth, destHeight),
        new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
        GraphicsUnit.Pixel);
 
    grPhoto.Dispose();
    return bmPhoto;
}

BlogEngine.NET 1.1 (an open source blog engine) was released in the middle of June and includes a theme that I created called GirlGeek! I wouldn't have normally submitted a feminine inspired theme but after designing my wife's blog (http://rebecca.sivers.co.uk) I thought it would be beneficial for the BlogEngine community to have a theme option for any female geeks out there that like this kind of look?!

The GirlGeek theme, like this one on my site, is loosly based on the Dirtylicious theme by Viktor Persson which was ported from WordPress to BlogEngine by Al Nyveldt. To be fair though I have heavily customised and altered the graphics and styling so it's only really using the original basic layout and positioning.

As well as the GirlGeek theme I have also knocked together a CoffeeHouse theme which is a more generic version of my blog's theme and I will make this available to the community as soon as I get a chance to organise it. You can see a screenshot of this theme below and if anyone wants this theme in the mean time then feel free to email me



I will hopefully find time over the next few months to work on some original themes to contribute to what I think is a really well coded .NET blog engine and also a really well run open source project! Stay posted!...