7 people following this project (follow)

Project Description


The BBImageHandler for DotNetNuke and ASP.NET gives users and module programmers the opportunity to use a handler that displays resized images, adds watermarks to images, creates  thumbnails of web pages or displays images stored in a database table without storing them to harddisk. Additionally it could be used to create a counter display.

The project is based on the Microsoft.Web.GeneratedImage Project here on Codeplex. I added a few things to that base implementation of an image handler. Rendering of gif images is improved with OctreeQuantizer, some special handlers are added and security functionality was added. Some parameters are now configurable thru web.config

Even this project is declared as DNN project, it is usable by every ASP.NET application. But I added a DNN installation manifest to the downloadable install file so it could be installed in DNN with the normal installation process.

Installation


for DNN: Use the normal installation of DNN
for all other ASP.NET Websites: Unzip install file, copy DLL to bin-folder, copy bbimagehandler.ashx file to web root and add the following to your web.config’s appSettings section:

<add key="BBImageHandler" value="EnableClientCache=true;EnableServerCache=true;EnableSecurity=true;ImageCompression=90" />

Parameters:

  • EnableClientCache: Set to true if client caching should be enabled
  • EnableServerCache: Set to true if server caching should be enabled
  • EnableSecurity: If set to true, only using bbimagehandler in a web page is allowed. Direct usage (eg: entering address in browser, no referer) is prohibited.  Also using it in a different domain is not possible (web page from http://www.domain-a.com uses http://www.domain-b.com/bbimagehandler.ashx...)
  • ImageCompression: quality of resulting image (0..100)

Usage


Resizing Image:

Resized Image including width-Tag:
<img src="bbimagehandler.ashx?File=Winter.jpg&width=150" />

image

Resized Image including height-Tag:
<img src="bbimagehandler.ashx?File=Winter.jpg&height=150" />

image

Resized Image with Border, BackColor and ResizeMode:
<img src="bbimagehandler.ashx?File=Winter.jpg&width=150&ResizeMode=FitSquare&BackColor=#F58719&border=10" /> (Escape '#' with '%23' in Url!)

image

Parameters:

  • width: width in pixel of resulting image
  • height: height in pixel of resulting image
  • resizemode:
    • fit: Fit mode maintains the aspect ratio of the original image while ensuring that the dimensions of the result do not exceed the maximum values for the resize transformation. (Needs width or height parameter)
    • fitsquare: Resizes the image with the given width as its longest side (depending on image direction) and maintains the aspect ratio. The image will be centered in a square area of the chosen background color (Needs width parameter, backcolor optional)
    • crop: Crop resizes the image and removes parts of it to ensure that the dimensions of the result are exactly as specified by the transformation.(Needs width and height parameter)
  • backcolor: color of background or/and  border when resizemode is fitsquare or fit.
  • border: border width in pixels around the image (added to width / height) when resizemode is fitsquare or fit.
  • format: jpg,png,bmp or gif, defines the format of the resulting image

Using watermarks:

<img src="bbimagehandler.ashx?File=Winter.jpg&height=150&watermarktext=watermark&watermarkfontcolor=white&watermarkposition=topleft" />

image

Parameters:

  • watermarkposition: TopLeft, TopCenter, TopRight, CenterLeft, Center, CenterRight, BottomLeft, BottomCenter, BottomRight
  • watermarktext: The text to display as watermark
  • watermarkfontfamily: the font name used for watermarktext. (Default:Verdana)
  • watermarkfontcolor: color name or html-color with leading '#' (eg. 'red', '#F0F0F0') (Default:Black)
  • watermarkfontsize: font size (Default: 14)
  • watermarkopacity: grade of opacity (0..100)

Images stored in Database

If your image is stored in a database field (SqlDbType:Image), you can use the following syntax:
<img src="bbimagehandler.ashx?db=SiteSqlServer&table=MyImages&ImageField=ImageData&idField=ImageID&idValue=3&height=150" />

image

Parameters:

  • db: key of connectionstring section in web.config (for DNN normally 'SiteSqlServer')
  • table: Name of the table in database
  • imagefield: name of the image-field containing the image data
  • idfield: name of the field containing the primary key (must be integer-id!)
  • idvalue: value of id

Webpage Thumbnail:

Url Thumbnail of Webpage:
<img src="bbimagehandler.ashx?Url=http:\\www.ebay.de&width=250&ratio=screen" />

image

Parameters:

  • url: Url of the Web page from which the thumbnail should be done
  • ratio:
    • full: Make a thumb of the full web page (Default)
    • screen: Make a thumb with dimensions 3:2 (cut of rest)
    • cinema: Make a thumb with dimensions 16:9 (cut of rest)

Counter

Using as counter:
<img src="bbimagehandler.ashx?File=Counter.gif&digits=8&counter=32477" />

image

Parameters:

  • File: Must be special counter image file with digits 0 to 9 with similar width per digit: image
  • digits: No of digits.
  • counter: Value to display

Last edited Jun 23 2011 at 7:23 PM by bitboxx, version 4