|Number of votes:||6|
EPiImage is a free module on EPiCode that provides basic image scaling functionality, as well as two new property types: EPiImage Property that extends “URL to image” with a preview, and EPiImageGallery Property that provides a editor friendly way to add pictures to a gallery including drag and drop sorting, description texts etc. It is not ment to do everything, but what it does it does well, and should be useful for any EPiServer project.
The EPiImageGallery Property in edit mode.
The EPiImage module is the result of two things.
EPiImage consist of 4 parts, and I will write a blog post about each:
In this blog post we will look at the first part: EPiImageResizer.
EPiImageResizer provides an out of the box automatic resize functionality to EPiServer. There is nothing to configure (although you can if you want) and it simply works. All resized images are stored in a cache folder for performance, and the resized image has a SEO friendly URL.
So lets see it in action.
As you can the original image is resized from 150 x 150 pixels to 100 x 100 pixels. The width and height attributes defines the maximum width and height of the resized image, in this case 100 x 100 pixels. The resized image is cached in the /Globals/Scaled/ folder in VPP, so the next time someone visits the page it simply uses the cached image.
In the above example we use the “ScaleToFit” transformation, but EPiImageResizer actually supports 3 different transformations:
This is what you normally want. It simply scales the image perserving the aspect (width/height) ration to fit inside the width and height you specify.
Scale To Fill
This transformation scales the image to fill the specified width and height maintaining the aspect ratio, but crops away anything that ends up outside the width/height box.
This transformation simply scales the image to the specified width and height without preserving the aspect ratio.
Simply download the module from EPiCode and install it using EPiServer Deployment Center. (It just copies in a few files, it doesn’t touch your web.config or require a rebuild)
Register the EPiImageResizer user control on the page you want to use it:
<%@ Register TagPrefix="EPiImage" TagName="EPiImageResizer" Src="~/EPiImage/UserControls/EPiImageResizer.ascx" %>
Then specify the url to the image to be scaled, max width and height and what transformation you would like:
<EPiImage:EPiImageResizer ImageUrl="/images/MyImage.jpg" Width="150" Height="150" Transformation="ScaleToFit" runat="server" />
The user control also have a bunch of other attributes for more advanced features:
|Attribute:||What does it do?|
|PropertyName||Specify the name of a property to fetch the image url from instead of using ImageUrl.|
|FallbackImageUrl||If the ImageUrl or PropertyName is empty, use this image instead.|
|LinkURL||Adds a <a href tag around the rendred img tag.|
|Alt||Adds an alt attribute to the rendered img tag|
|Tooltip||Adds a title attribute to the rendered img tag for mouse over tooltips in all browsers|
|CssClass||Adds a class attribute to the rendered img tag|
|CssStyle||Adds a style attribute to the rendered img tag|
|LinkCssClass||Adds a class attribute to the a href tag.|
Feel free to email or twitter me with your feedback: @ahaneng :-) Also if you like to help out with debugging/testing let me know.
Word of warning: I want to keep this module small and simple, and no, it won’t solve everybody's needs, but it will solve basic image needs for most small/medium projects. So that means no YouTube/Viddler/Flickr support etc. (But hey, it is open source so feel free to fork it if you really want to) :-)
And finally: Thank you to Making Waves for donating it to EpiCode!
Next post: EPiImage Part 2: EPiImage Property