Documentation > CMS Template API Library > Img > CropImage(Int32,Int32,Int32,Int32,Int32,Int32,Int32)

CropImage

Crop a an image out of the original (current instance) using the coordinate defined by x,y,xx,yy, then scale it using width and height as in the CreateThumbnail call. The final image dimensions will not necessarily match the width and height unless the aspect ratio is preserved.

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


Returns

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

Parameters

NameDescriptionType
width The width used to scale the final image. System.Int32
height The height used to scale the final image. System.Int32
x The first x-coordinate (left) in pixels for the box used to cut out the cropped image. System.Int32
y The first y-coordinate (top) in pixels for the box used to cut out the cropped image. System.Int32
boxWidth The width in pixels for the box used to cut out the cropped image. System.Int32
boxHeight The height in pixels for the box used to cut out the cropped image. System.Int32
qualityByPercent Optional: The quality of the resulting image as a percent. Defaults to 75 System.Int32

Code Example

C#

Sample:

             
               // Usually called from post_input.aspx
                 Img img = context.UploadedFiles["my_photo"].Img;
            
                 if (!img.HasError)
                 {
                 // It's likely lasso params from the input would be used for these dimensions
                  ImgResult res = img.CropImage(300, 300, 0, 0, 500, 500);
                  if (res.HasError)
                  {
                     context.Error = "Upload Error cropping image on " + value + " error: " + res.ErrorMessage;           
                   }  
                  }
                 else
                 {
                   context.Error = "Image Error Loading on " + context.UploadedFiles["my_photo"].Path + " error: " + img.ErrorMessage;           
                 }
             
             
             

Connect with Crownpeak