trim method

void trim(
  1. [int top,
  2. int right,
  3. int bottom,
  4. int left]
)

The trim parameter lets you trim an image from the edges. This is especially useful for removing border or white spaces that the downloaded images usually come with. The value for this parameter can be given in pixels or percentage. You can specify values for top, right, bottom, and left edges of an image. For example, to trim the top edge by 25px, right edge by 50px, bottom edge by 75px and left edge by 100 provide trim as comma separated value like, 25,50,75,100

For more details, Read documentation: https://www.contentstack.com/docs/developers/apis/image-delivery-api/#trim-images

Example:

final stack = contentstack.Stack(apiKey, deliveryToken, environment);
final imageTransformation = stack.imageTransform(imageUrl);
final response = await imageTransformation.trim(25).fetch();

Implementation

void trim([int top, int right, int bottom, int left]) {
  final trimLRBL = [];
  if (top != null) {
    trimLRBL.add(top);
  }
  if (right != null) {
    trimLRBL.add(top);
  }
  if (bottom != null) {
    trimLRBL.add(bottom);
  }
  if (left != null) {
    trimLRBL.add(left);
  }
  final joinedValue = trimLRBL.join(', ');
  query.append('trim', joinedValue);
}