Monday, March 11, 2013

ImageProperty for EPiServer7



I’m happy to inform about a new addition to OpenWaves project. Grzegorz Wiechec – a colleague of mine at MakingWaves – contributed his first EPiServer7 property – ImageProperty.

The property enhances Url property by adding improved edit mode experience and server side scaling of images in view mode.

Getting started

To use the property add the following UIHint to any Url property.

using OpenWaves.EPiServer.ImageProperty; 

...

[UIHint(ImageProperty.UIHint)] 
public virtual Url Image1 { get; set; }

Form editing mode

Clicking on the property opens a file browser.


clip_image001[2]

Images can also be drag-dropped from the file manager.


clip_image003

After a picture is selected, the property shows a server-side scaled thumbnail.


clip_image005

On-page editing mode

In this mode the property is rendered as server-side transformed image and supports drag and drop of images from the file manager.


clip_image007

To enable enhanced on-page editing support, use <ow:ImageProperty> control in the page template. ImagePeoprty control is a wrapper around <EPiServer:Property> control that uses RenderSettings dictionary to pass relevant information to PropertyImageControl which in turn uses OpenWaves.ImageTransformations.Controls.Image control to enable server-side image transformations.

<ow:ImageProperty runat="server" PropertyName="Image1" 
    Transformation="ScaleToFill" 
    ImageWidth="200" ImageHeight="200" /> 

Transformation attribute can be any of the transformations supported by <ow:Image> property. See: https://openwaves.codeplex.com/wikipage?title=Image for more details.

Installation

  1. Install OpenWaves.EPiServer.ImageProperty nugget package.
  2. Add an initializable module that registers WebImageTransformationsModule used to perform server-side image transformations.
    [InitializableModule] 
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] 
    public class Bootstrapper : IInitializableModule 
    { 
        public void Initialize(InitializationEngine context) 
        { 
            ServiceLocator.SetResolver(new BasicResolver() 
                .RegisterWebImageTransformationModule(
                    HostingEnvironment.VirtualPathProvider,
                    "~/Content/Images/Transformed")); 
        } 
    
        public void Uninitialize(InitializationEngine context) 
        { } 
    
        public void Preload(string[] parameters) 
        { }
    }

Source code

Source code is available at: https://openwaves.codeplex.com