Trimming an image
Trim an image by the same amount or by different amounts of pixels from any or all four sides by appending the /trim/ command to your image transformation URL.
Procedure
- Write the image transformation base URL, for example, http://localhost/cidpath/.
- Append
/trim/to this URL to indicate that you want to trim the image. - To trim all four sides of the image by the same amount of pixels, append
AMOUNT/, where AMOUNT is the amount of pixels to trim on all sides.For example, the colored part of the image below shows the result of applying
trim/100/to the original image (in greyscale): - Alternatively, to trim the top and bottom sides of the image by one amount of pixels, and the left and right sides by another amount, append
TOPBOTTOMAMOUNT~LEFTRIGHTAMOUNT/, where TOPBOTTOMAMOUNT is the amount of pixels to trim on the top and bottom, and LEFTRIGHTAMOUNT is the amount of pixels to trim on the left and right. (Use the value0to indicate that no trimming should occur on the side to which the amount refers.)For example, the colored part of the image below shows the result of applying
trim/100~200/to the original image (in greyscale): - Alternatively, to trim the top of the image by one amount of pixels, the bottom by another amount, and both the left and right sides by yet another amount, append
TOPAMOUNT~LEFTRIGHTAMOUNT~BOTTOMAMOUNT/, where TOPAMOUNT is the amount of pixels to trim on the top, LEFTRIGHTAMOUNT is the amount of pixels to trim on the left and right, and BOTTOMAMOUNT is the amount of pixels to trim on the bottom. (Use the value0to indicate that no trimming should occur on the side or sides to which the amount refers.)For example, the colored part of the image below shows the result of applying
trim/100~150~200/to the original image (in greyscale): - Alternatively, to trim each side of the image by a different amount of pixels, append
TOPAMOUNT~RIGHTAMOUNT~BOTTOMAMOUNT~LEFTAMOUNT/, where TOPAMOUNT is the amount of pixels to trim on the top, RIGHTAMOUNT is the amount of pixels to trim on the left and right, BOTTOMAMOUNT is the amount of pixels to trim on the bottom, and RIGHTAMOUNT is the amount of pixels to trim on the right. (Use the value0to indicate that no trimming should occur on the side or sides to which the amount refers.)For example, the colored part of the image below shows the result of applying
trim/50~100~150~200/to the original image (in greyscale): - Do one of the following:
- Append
source/followed by the alias of a location or image. If the alias refers to a location, also append a path (optionally) and a file name (mandatory). For example,source/logo,source/repository/myfile.jpgorsource/imageroot/myfolder/myfile.png. - Append the full URL of an image, for example,
www.example.com/images/example.gifor, if the URL uses the HTTPS protocol,https://www.example.com/images/example.gif.
- Append
- Access the URL to perform the trim and retrieve the trimmed image. If any amount to trim specified is larger than the side or sides to which it refers, a 1x1 transparent GIF image is returned instead.