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("<img 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.
89cbfa89-507f-41a6-823f-4453c9e23f42|4|4.8