External: Holmok Image Handler

Summary:

This control wasn't made by me, so it has only this page devoted to it (with installation, contacts, licence...).
The Holmok Image Handler is your easy to use solution for all of your web image needs. Since it is a .NET HttpHandler, once deployed you will not have to add any controls, write any code to take advantage of the Holmok Image Handler feature set.
The Source file is also included (.cs).
Features:
Dynamic thumbnail generation. Dynamic image resizing. Watermarking you images. Securing your images against external referrers. Securing your images against no referrers. Source code is available.

Installation:

  1. Copy the “HolmokImageHandler.dll” into the “bin” directory of your website/web application/virtual directory.
  2. Add the following lines to your “<system.web>” element of your “web.config” file.
    <httpHandlers>
       <add verb="*" path="photos/*.jpg"    type="Holmok.HttpHandlers.ImageHandler,HolmokImageHandler"/>
    </httpHandlers>

    Note: This is an example of applying the handler to all the “jpg” files in the “photos” directory. You can apply the Handler to more than one directory and to any of the following image types: “bmp”, “gif”, “jpg”, “png”. You will just need to add more “add” elements to the “httpHandlers” element for each directory and each image type.

  3. Add the “appSettings” from the “sample_web.config” file to your web.config file and adjust the values to your configuration. Here is an explanation of the application settings:
  4. In the IIS Management Console, right click the website/web application/virtual directory you installed the handler and select properties.
  5. Go to the “Directory” or “Home Directory” tab in this dialog.
  6. Under “Application Settings” click the configuration button.
  7. In the “Mapping” tab click the “Add” Button.
  8. Click the browse button and navigate to and select the .NET ISAPI filter. This usually can be found here: “C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll”.
  9. Next to extension enter the extension of the image files you want to use with the handler (i.e. ‘.jpg’ – without the single quotes for jpeg images).
  10. Click the “OK” button.
  11. Repeat steps 7 through 10 for each image type you want to use for the handler.

Usage:

Now create an HTML page in the website/web application/virtual directory you installed the handler that has an image tag like this <img src=”photos/hous.jpg?thumb=1”>. Where the “src” attribute points to an image that will be handled by the image handler. That is whatever path you have set up in the “httpHandlers” element in the “web.config” for your application. And remember to add the “?thumb=1” to the end. That image should now be resized server side and show up as a thumbnail of the image.

Here is an explanation of other attributes or parameter to add to your image to manipulate it.

  1. <imgsrc=”photos/hous.jpg?thumb=1”> : Generates a thumbnail the size you configured in your “web.config” file.
  2. <imgsrc=”photos/hous.jpg?p=50”> : Resizes the image 50%. < li><imgsrc=”photos/hous.jpg?w=640&h=480”> : resizes the image to 640x480 pixels.
  3. <imgsrc=”photos/hous.jpg?w=400”> : resizes the image so that the width is 400 and it maintains the aspect ration of the images dimensions.
  4. <img src=”photos/hous.jpg?h=400”> : resizes the image so that the height is 400 and it maintains the aspect ration of the images dimensions.

Licence Agreement:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

This permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.