7

I have implemented an ECL provider which generates thumbnails of my images. I would now like to show some form of overlay to indicate whether the item is checked out (in the external system), published, and eventually add a restricted watermark.

Are there any examples of overlaying the standard checked-out or published icons on ECL items, or samples of how to use the GetThumbnailImage() method with the IList<IThumbnailOverlay> thumbnailOverlays overload that I see in the ECL API docs? Would this be an appropriate way to implement such functionality, or should I just manipulate the byte array which is returned by the GetThumbnailImage() method of my class implementing IContentLibraryContext?

1 Answer 1

4

You can get the overlay icon like this:

int actualSize;
byte[] iconData = Library.HostServices.GetIcon(
                      Library.IconBasePath,
                      null,
                      "your-icon-name",
                      16,
                      out actualSize);

As CreateThumbnailOverlay requires a stream, you need to create a memory stream. So the code will look something like this:

using (MemoryStream iconStream = new MemoryStream(iconData, false))
{
    // This implies item is a MultiMediaItem already loaded and GetContent
    // returns an actual image, if not you need to get the main thumbnail
    // image by other means
    IContentResult content = item.GetContent(null);
    try
    {
        IList<IThumbnailOverlay> overlays = new List<IThumbnailOverlay>
        {
            // maxWidth and maxHeight specifies the requested thumbnail size,
            // so this icon is placed in the lower left corner.
            Library.HostServices.CreateThumbnailOverlay(
                 0,
                 maxHeight - actualSize,
                 actualSize,
                 actualSize,
                 iconStream)
        };

        return Library.HostServices.CreateThumbnailImage(
            maxWidth,
            maxHeight,
            content.Stream,
            maxWidth,
            maxHeight,
            overlays);
    }
    finally
    {
        content.Stream.Close();
    }
}

Tridion thumbnails do not display overlays for checked out etc. This is the reason ECL doesn't add the overlays automatically.

You can of course manipulate the bytes directly - but as ECL runs in a Windows service you can't use the classes within System.Drawing. You can use the WPF classes, but these require an STA thread.

There might be a third party library you can use to manipulate images on a MTA thread, but unless you require something more than just overlaying images I would recommend sticking to the methods provided by ECL.

3
  • Thanks Lars, this code explains a lot, but I am still not sure where I should be putting this? I am also not clear how this can get the existing Published and CheckedOut overlays. Are there some specific "your-icon-name" values for this? Jun 18, 2013 at 13:39
  • This is pretty much a complete implementation of IContentLibraryContext.GetThumbnailImage - the only part that is missing is where it initialize the item variable - Which could simply be a call to GetItem. There are no easy way to get hold of the checked out etc icons - Either include them with your provider, or try to locate them on the server. But again: Tridion normally does not display these overlays on thumbnails - so do you really need them or do you just think you need them (like I did)? :) Jun 18, 2013 at 14:58
  • Sorry, I missed the part where you mention it's checked out on the remote system you want to display. I would consider not using standard Tridion icons for this, after all the item can also be checked out in Tridion. Jun 18, 2013 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.