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

CropImage

Recommended Version: Crop the current image stored on the uploadedFile using the box defined on the input form using the lasso. "Lasso" properties must be set on ShowAcquireParams when they are passed to Input.ShowAcquireImage

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


Returns

ImgResult. Contains the new Img. Use HasError to check for errors.

Parameters

NameDescriptionType
uploadedFile UploadedFile that contains an Image CrownPeak.CMSAPI.UploadedFile
thumbnailKey A key used to save the result System.String
qualityByPercent Optional: The quality of the resulting image as a percent. Defaults to 75 System.Int32

Code Example

C#

Sample:

             
            
              // input.aspx : Important: First have an upload with lasso params in the input form
              
              ShowAcquireParams aParams = new ShowAcquireParams();
              aParams.DefaultFolder = "/Assets/images";
              aParams.ShowLasso = true;
              // final cropped image will be scaled down to 100 pixels
              aParams.LassoHeight = 100;
              aParams.LassoWidth = 100;
              // initial dimensions for the selection "lasso", after a successful crop the current dimensions will be saved and used on the input form the next time.
              aParams.LassoBoxTop = 0;
              aParams.LassoBoxLeft  = 0;
              aParams.LassoBoxWidth = 200;
              aParams.LassoBoxHeight = 200;
              
              //The original will be scaled down to not more than 600 on each side
              aParams.AddAdditionalImage("original_image", 600,600);
                
              Input.ShowAcquireImage("Original", "original_image", aParams);
              
             // post_input.aspx:
             // Take the file uploaded with the name "original_image" crop it as defined on the input form and store it with the name "cropped_Image"
             ImgResult img = context.InputForm.CropImage(context.InputForm.UploadedFiles["original_image"], "cropped_image");
             if (img.HasError)
             {
               context.Error "Crop error " + img.ErrorMessage;
             }
             
             

Connect with Crownpeak