Publishing SharePoint Image renditions with PnP Provisioning

Apr 20, 2017

A couple of days ago, I had to work again with Image Renditions in SharePoint. We’re developing a intranet for one of our customer and that solution partially relies on publishing features.

Just as a reminder, image renditions were introduced back in 2013 to help you serve the most optimized version of an image without having the information workers caring about sizes and whatnot or without you having to resize images with code.

If you haven’t come across those, here are very good resources about the subject.

https://www.eliostruyf.com/provision-image-renditions-to-your-sharepoint-2013-site/

https://www.eliostruyf.com/image-renditions-december-cumulative-update-sharepoint-2013/

Now in our case we’re heavily leveraging pnp provisioning to take care of creating files, site columns, content types and so on for us. Hence the question: is it possible to configure Image Renditions using PnP provisioning?

As a matter of that it is, you can go ahead and configure all your templates from the site settings and then grab the file located in ~/SiteCollection/_catalogs/masterpage/PublishingImageRenditions.xml

The last thing you need to do is updating your pnp template to deploy that new file for you, here is the snippet:

<pnp:Files>
    <pnp:File Src="PublishingImageRenditions.xml" Folder="{SiteCollection}/\_catalogs/masterpage" Overwrite="true" Level="Published">
        <pnp:Properties>
            <pnp:Property Key="ContentTypeId" Value="0x01010012BCF119622FF14793A8A38D5831F25C" />
            <pnp:Property Key="ContentType" Value="Document" />
        </pnp:Properties>
    </pnp:File>
</pnp:Files>

As a bonus, here is a snippet to make sure publishing features are turned on, which is required by Image Renditions

<pnp:Features>
    <pnp:SiteFeatures>
        <pnp:Feature ID="f6924d36-2fa8-4f0b-b16d-06b7250180fa" Description="SharePoint Server Publishing Infrastructure" />
    </pnp:SiteFeatures>
    <pnp:WebFeatures>
        <pnp:Feature ID="94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" Description="SharePoint Server Publishing" />
    </pnp:WebFeatures>
</pnp:Features>

Last edited Apr 15, 2024 by Vincent Biret


Tags: