3

I am a web developer and my company uses SDL Tridion 2011. Its a great cms. Currently we create and publish a news article which sometimes has a fairly large size of an image embedded. We handle resizing down this image on the script side, however, we would like to change this to the following flow if possible.

  1. User creates a new image component under 'News/Images' and upload an image (example image size would be w:2955px x h:1866px)
  2. In Tridion, every image is saved in this directory will be resized and copied in a new directory 'News/Images/resized'

Is this possible? If so, please point to me right information/direction. Also, any advice/suggestion is much appreciated.

3 Answers 3

6

You can resize (or crop, which is another common use-case) the image at different phases:

  1. When the image is uploaded to Tridion ("baked" in the Content Manager)
  2. When the image is published to Content Delivery ("baked" on publish)
  3. When the image is delivered to the visitor ("fried" on request)

Each of these approaches has their own advantages and disadvantages. For example: when you resize the images after uploading (phase 1), you can inspect the resized images in the CMS and if necessary improve it manually. But you have derived content in your CMS (which is a form of denormalization) and the editors will have to pick the correct image size for their situation (error prone).

Consider limiting the allowed Schemas to a specific Multimedia Schema to reduce errors if taking this approach. The uploaded image could be one Schema (e.g. named "High Resolution Upload" or similar), possibly set as the default for News > Images. The resized image could be a different Schema (e.g. Default Multimedia), which the News Article allows in its image field. CMS editors would only be able to pick the right type of image.

Nick offers solutions that work in phases 2 and 3.

If you want the image to be resized when it is uploaded to Tridion (phase 1), you should probably look into writing your own event handler that triggers when the image uploading is completed and then generates the derived images.

2
  • 1
    The slang or jargon we've used to describe these phases are "bake" in the CMS, bake during publish, or "fry" in delivery. To reduce CMS user error, consider different Schemas for the original uploaded images and the resized versions. The News Article Schema field for the image could then limit which image CMS users are allowed to use (i.e. only allow the smaller versions). Dec 1, 2014 at 21:35
  • Done. I incorporated the info in my comment into the community wiki (long live the Midas Rule). :-) Dec 2, 2014 at 20:27
4

There is a TBB you can use out of the box called Image Resizer. In its parameters you can specify to which size to change the image to. It publishes the image to the same location as all the images go, but under a resized filename and variant ID so that there is no conflict. The way you're expected to use the images from this TBB is in conjunction with the TBBs in Default Finish Actions. In my experience, I have never had a use case that this TBB would be a fit for. So have usually developed custom TBBs to do the resizing for specific use cases.

Another option is to use the Contextual Image Delivery Web Service from SDL. You can read about it in the docs here: http://docs.sdl.com/LiveContent/content/en-US/SDL%20Contextual%20Image%20Delivery-v1. There are also a few blogs on this subject:

2
  • This question is quite common (though it was asked more often back in the forum days). Feel free to merge my answer with yours to come to one reference answer. Nov 29, 2014 at 15:34
  • 1
    A custom approach for changing the image size on publish would likely use AddBinary(), which allows you to change the location, path, name, and "variant" identifier for an image. A typical use case would be to place images in a certain location in delivery or create thumbnail versions of images. The main restriction on such image variants is the same variant can't go to multiple locations and multiple variants can't go to the same location. Dec 1, 2014 at 21:41
0

The API you want to look at for your specific case is the Event System. You can hook the save event via

using System;
using System.Text;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.ContentManagement;
using System.IO;

namespace MyEventHandlers
{
[TcmExtension("MyEventHandlerExtension")]
public class MyEventHandler : TcmExtension
{
    public MyEventHandler()
    {
        Subscribe();
    }

    public void Subscribe()
    {
        EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSave, EventPhases.TransactionCommitted);
    }

    private void OnComponentSave(Component subject, CreateEventArgs args, EventPhases phase)
    {
        //Your code goes here
    }
}
}

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.