Documentation > CMS Template API Library > Asset > CreateThumbnail(UploadedFile,String,Int32,Int32,Int32,Boolean)
CreateThumbnail
Creates a thumbnail of the specified size from the currently loaded image. A ThumbnailKey is required. The resulting image will be stored on the asset unless we are in upload.aspx, in that case it will be saved to the asset or current panel at the time the input form is saved. To change the currently uploaded image in place use the uploadContext.UploadedFile.UploadKey as the thumbnail Key. Important note, if calling from upload.aspx and the thumbnail key is not the same as the upload, make sure that the thumbnail key is in the list of strings passed as the hiddenFields parameter of the Input.ShowAcquireImage() call. 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)
Returns
An ImgResult.
Parameters
Name | Description | Type |
---|---|---|
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. Defaults to 75. | 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. Defaults to true. | System.Boolean |
Code Example
C#
// Usually called from upload.aspx UploadedFile imageUpload = context.UploadedFile; // my_photo_thumbnail was used in input.aspx because we want to display the thumbnail when we edit, not the possibly large original if (imageUpload.Matches("my_photo_thumbnail")) { asset.SaveUploadedFile("my_photo", imageUpload); // it gets overwritten later when it is resized to 300x300 ImgResult res = asset.CreateThumbnail(imageUpload, "my_photo_thumbnail", 300, 300); if (res.HasError) { context.Error = "Upload Error creating thumbnail on " + value + " error: " + res.ErrorMessage; } } else { context.Error = "Upload Error Loading on " + value + " error: " + img.ErrorMessage; }