Documentation > CMS Template API Library > PanelEntry > CreateThumbnail(UploadedFile,String,Int32,Int32,Int32)

CreateThumbnail

Creates a thumbnail of the specified size from the UploadedFile, it must be an image. A ThumbnailKey is required. The resulting image will be stored on the panel. Note: Due to memory limitations, the pixel count of the source image cannot be more than 10 million. Note: Do not include the post fix ":..." part of the name. Use the shortname "my_field", not "my_field:1"

public CrownPeak.CMSAPI.ImgResult CreateThumbnail(UploadedFile,String,Int32,Int32,Int32)

Parameters

NameDescriptionType
uploadedFile The image to be used to create the thumbnail CrownPeak.CMSAPI.UploadedFile
thumbnailKey The Key used to refer to the thumbnail later as part of the asset's content. System.String
width The width. System.Int32
height The height. System.Int32
qualityByPercent Optional: The Quality of the saved JPG as a percent. Higher numbers have higher quality, but also bigger sizes. System.Int32

Code Example

C#

Sample:
// Usually called from post_input.aspx     
List<PanelEntry> panels = context.InputForm.GetPanels("imageList");

foreach(PanelEntry panel in panels)
{
  if (panel.UploadedFiles["my_photo"] != null)
  {
    ImgResult result = panel.CreateThumbnail(panel.UploadedFiles["my_photo"],"my_photo_thumbnail_panelpost_50_", 50,50);
    if (result.HasError)
    {
      panel["Error"] = result.ErrorMessage;
    }
  }
}

Connect with Crownpeak