Using ImageHandler.Serving event ?

Nov 29, 2011 at 5:34 PM
Edited Nov 29, 2011 at 5:38 PM

Rtur ,

Could you help me how use Serving event for image manipulation ?

I am clueless about how to collect the image in serving event.

BlogEngine.Core.Web.HttpHandlers.ImageHandler.Serving += new EventHandler<EventArgs>(ImageHandler_Serving);

void ImageHandler_Serving(object sender, EventArgs e)
  {
      throw new NotImplementedException();
  }

Coordinator
Nov 30, 2011 at 3:13 AM

In the code below, "fileName" is a name of the file being served, for example "/2011/11/MyPic.png". Whatever you do with it is up to you.

static MyExtension()
{
    BlogEngine.Core.Web.HttpHandlers.ImageHandler.Serving += ImageHandler_Serving;
}

static void ImageHandler_Serving(object sender, System.EventArgs e)
{
    var fileName = sender.ToString();
    // do something with image file here
}

Nov 30, 2011 at 6:56 PM
Edited Nov 30, 2011 at 6:57 PM

Thanks for post reply rtur,

I tested but it seems nothing happened.

Suppose i put an empty string in filename (fileName=String.Empty) the post images still display.

I believe it should have gone like this <img width="300" src="http://www.xx.com/image.axd?picture=<empty>" >

What approaches you people apply (on your blogs) for thumbnail of posts images in BE ?

Honestly speaking image thumbnail (post) is so confusing that i still don't know if there is any in built method for ImageList array of post or not (like word press) .This disadvantage is also restricting beautiful themes creation on BE platform as most blog themes have thumbnail slots as well for Top Posts,Popular Posts,Recent Posts..

Coordinator
Nov 30, 2011 at 7:39 PM
Edited Nov 30, 2011 at 7:43 PM

Serving event just passes file name as a string and it doesn't matter if you re-assign fileName variable to something else - it is just a local variable. Event handler useful if you want to examine images before sending it to the client browser. Then you could cancel event if you don't want to send image or maybe even resize image on the server if it is too big or add watermark etc. - any image manipulation that C# let you do.

To set image size, you don't need to use handler - simple CSS styling will do fine. That what most themes are doing, and nothing stopped me from adopting any wordpress theme before :)

There are also widgets like popular posts, top posts and featured posts that you can use and/or modify to your needs.

Also this extension might be of interest for image handling.

Nov 30, 2011 at 8:21 PM
rtur wrote:

Serving event just passes file name as a string and it doesn't matter if you re-assign fileName variable to something else - it is just a local variable. Event handler useful if you want to examine images before sending it to the client browser. Then you could cancel event if you don't want to send image or maybe even resize image on the server if it is too big or add watermark etc. - any image manipulation that C# let you do.

To set image size, you don't need to use handler - simple CSS styling will do fine. That what most themes are doing, and nothing stopped me from adopting any wordpress theme before :)

There are also widgets like popular posts, top posts and featured posts that you can use and/or modify to your needs.

Also this extension might be of interest for image handling.

Thanks for clearing doubts on handler.

You said that simple CSS styling will do fine for image size...But resizing with css will not reduce bytes and suppose there are 15 post images ( Top,Featured,Recent ) then loading of home page would get affected...

I hope you are getting my point....

Coordinator
Nov 30, 2011 at 8:42 PM

Sure. If you have image-heavy site, you might need a whole strategy around it to be really efficient. For example, have upload process create multiple image sizes including thumbnails of every image, do caching, and only then have CSS intelligently use correct image for given template. Kind of like it does Flikr or Picasa and others photo-related sites. For blog it would probably be overkill, although nice to have. You can add this as feature request and with enough people to care about it, this can be a go...

Dec 1, 2011 at 4:20 AM

The discussion was useful ! I would be now looking to create & share (on dnbegallery) some new widgets with that strategy . Thank you very much , rtur !