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

CreateThumbnail

Creates a thumbnail of the specified size from an uploaded files. A ThumbnailKey is required. The resulting image will be stored on the asset at the end of post_input. Note: Due to memory limitations, the pixel count of the source image cannot be more than 10 million.

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

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
preserveAspectRatio Optional: Pass false if you want the thumbnail to be generated with exactly the size of the passed in width and height.Available in builds 3451 and up. System.Boolean

Code Example

C#

Sample:

             
            
              // Usually called from post_input.aspx
              
              if (context.InputForm.UploadedFiles["my_photo"] != null)
              {
                ImgResult result = context.InputForm.CreateThumbnail(context.InputForm.UploadedFiles["my_photo"], "my_photo_thumbnail_on_post", 50,50);
                if (result.HasError)
                {
                  panel["Error"] = result.ErrorMessage;
                }
              }
              
             
             
             

Connect with Crownpeak