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:
-
Copy the “HolmokImageHandler.dll” into the “bin” directory of your website/web
application/virtual directory.
-
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.
-
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:
-
hih thumbnail size
-
A number greater than 0.
-
The maximum height or width of a thumbnail (aspect ratio of the image will be
maintained)
-
hih watermark minimum wdith
-
A number greater than 0.
-
Any image greater then this width will be watermarked
-
hih watermark type
-
String (“none”, “text”, or “graphic”)
-
Which type of watermark to use
-
hih watermark graphic
-
String (Absolute path (i.e. /MyApp/images/watermark.gif) to watermark graphic
-
hih watermark graphic transparent color
-
HTML color (i.e. #FFFFFF)
-
Represents color to make transparent in the watermark graphic
-
Leave out to ignore transparency
-
hih watermark text
-
String
-
This is the text to use in a text watermark
-
hih watermark position
-
String (“top left”, “top right”, “bottom left”, “bottom right”)
-
The position of the watermark
-
hih watermark x
-
Number
-
Distance (in pixels) along the x-axis or width from the corner described in the
watermark position.
-
hih watermark y
-
Number
-
Distance (in pixels) along the y-axis or height from the corner described in
the watermark position.
-
hih watermark font
-
String
-
Name of the font (must be installed on the server) of the text watermark
-
hih watermark color
-
HTML color (i.e. #FFFFFF)
-
Color of text watermark
-
hih watermark size
-
Number
-
Size (in pixels) of font in text watermark
-
hih watermark shadow color
-
HTML color (i.e. #FFFFFF)
-
Represents color shadow used in the text watermark
-
Leave this element to have no dropshadow.
-
hih watermark shadow distance
-
Number
-
Distance (in pixels) to offset text watermark shadow
-
hih no access
-
String (Absolute path (i.e. /MyApp/images/watermark.gif) to graphic or html
page to use when invalid access is requested.
-
If you reference an image, that will be served in place of the requested
image
-
If you reference a non-image (html, aspx page, etc.) the user requesting that
image will be redirected to the given reference.
-
hih allow external referrers
-
String (“yes” or “no”)
-
Determines whether or not external sites may reference images.
-
hih allow no referrers
-
String (“yes” or “no”)
-
Determines whether or not direct non-contextual access is allowed to your
images.
-
In the IIS Management Console, right click the website/web application/virtual
directory you installed the handler and select properties.
-
Go to the “Directory” or “Home Directory” tab in this dialog.
-
Under “Application Settings” click the configuration button.
-
In the “Mapping” tab click the “Add” Button.
-
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”.
-
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).
-
Click the “OK” button.
-
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.
-
<imgsrc=”photos/hous.jpg?thumb=1”> : Generates a thumbnail the size you
configured in your “web.config” file.
-
<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.
-
<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.
-
<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.