LCOV - code coverage report
Current view: top level - lib/src - image_transform.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 111 118 94.1 %
Date: 2020-10-22 15:41:59 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:async';
       2             : import 'dart:convert';
       3             : 
       4             : import 'package:contentstack/client.dart';
       5             : import 'package:contentstack/contentstack.dart';
       6             : import 'package:contentstack/src/image/filter.dart';
       7             : import 'package:contentstack/src/image/fit.dart';
       8             : import 'package:contentstack/src/image/format.dart';
       9             : import 'package:contentstack/src/image/orientation.dart';
      10             : import 'package:contentstack/src/query_params.dart';
      11             : 
      12             : ///Image Delivery APIs retrieve, manipulate and/or convert the retrieved image file,
      13             : ///and deliver it to your web or mobile properties.
      14             : ///Learn more about [ImageTransformation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/)
      15             : class ImageTransformation {
      16             :   final String _imageUrl;
      17             :   final HttpClient client;
      18             :   final Map<String, String> queryParameter = <String, String>{};
      19           1 :   final URLQueryParams query = URLQueryParams();
      20             :   ImageTransformation(this._imageUrl, this.client);
      21             : 
      22             :   /// The auto function lets you enable the functionality that automates
      23             :   /// certain image optimization features.
      24             :   /// As of now, there is only one possible value for this field, i.e.,
      25             :   /// webp. When the auto parameter is set to webp,
      26             :   /// it enables WebP image support. WebP images have higher compression
      27             :   /// rate with minimum loss of quality.
      28             :   ///
      29             :   /// For more details, Read documentation:
      30             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#automate-optimization
      31             :   ///
      32             :   /// Example:
      33             :   ///
      34             :   /// ```dart
      35             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
      36             :   /// final imageTransformation = stack.imageTransform(imageUrl);
      37             :   /// await imageTransformation.auto(auto: 'webp', format: 'pjpg').fetch();
      38             :   /// ```
      39           1 :   ///
      40             :   void auto({String auto, String format}) {
      41           2 :     if (auto != null) {
      42             :       query.append('auto', auto);
      43             :     }
      44           2 :     if (format != null) {
      45             :       query.append('formate', format);
      46             :     }
      47             :   }
      48             : 
      49             :   ///The bg-color function lets you set a backgroud color for the given image.
      50             :   ///This is useful when applying padding or for replacing
      51             :   ///the transparent pixels of an image.
      52             :   ///There are three possible types of values for this [bgColor] is string .
      53             :   ///It can accept hexadecimal, combination of (Red, Blue, Green)
      54             :   ///and (Red, Blue, Green, Alpha).
      55             :   ///
      56             :   /// For more details, Read documentation:
      57             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#background-color
      58             :   ///
      59             :   /// Example:
      60             :   ///
      61             :   /// ```dart
      62             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
      63             :   /// final imageTransformation = stack.imageTransform(imageUrl);
      64             :   /// final response = await imageTransformation.bgColor('cccccc').fetch();
      65             :   /// ```
      66             :   void bgColor(String bgColor) {
      67             :     query.append('bg-color', bgColor);
      68           1 :   }
      69           3 : 
      70             :   ///
      71             :   /// The blur parameter allows you to decrease the focus and
      72             :   /// clarity of a given image. To specify the extent
      73             :   /// to which you need to increase the blurriness of an image,
      74             :   /// use any decimal number (float) between 1 and 1000.
      75             :   ///
      76             :   /// For more details, Read documentation:
      77             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#blur
      78             :   ///
      79             :   /// Example:
      80             :   ///
      81             :   /// ```dart
      82             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
      83             :   /// final imageTransformation = stack.imageTransform(imageUrl);
      84             :   /// final response = await imageTransformation.blur(3).fetch();
      85             :   /// ```
      86             : 
      87             :   void blur(int blur) {
      88             :     query.append('blur', blur.toString());
      89           1 :   }
      90           2 : 
      91           2 :   /// The brightness parameter allows you to increase or decrease the intensity
      92           1 :   /// with which an image reflects or radiates perceived light.
      93           2 :   /// To specify brightness for an image, use a whole number (integer)
      94           1 :   /// between -100 and 100.
      95           2 :   /// You can also define brightness using any decimal number
      96           1 :   /// between -100.00 and 100.00
      97           2 :   /// To increase the value of the brightness parameter of an image,
      98           1 :   /// pass a positive value or negative value
      99           2 :   /// For more details, Read documentation:
     100           1 :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#brightness
     101           2 :   ///
     102           1 :   /// Example:
     103           2 :   ///
     104             :   /// ```dart
     105             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     106             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     107             :   /// final response =  imageTransformation.brightness(20);
     108             :   /// ```
     109             :   void brightness(int brightness) {
     110             :     query.append('brightness', brightness.toString());
     111             :   }
     112             : 
     113             :   ///
     114             :   /// The canvas parameter allows you to increase the size of the canvas that
     115             :   /// surrounds an image. You can specify the height and width of
     116             :   /// the canvas area in pixels or percentage or define the
     117             :   /// height and width of the aspect ratio of the canvas. You can also define
     118             :   /// the starting point for
     119             :   /// the canvas area or offset the canvas on its X and Y axis.
     120             :   ///
     121             :   /// [canvasValue] could be in the type of string,
     122             :   /// It could be in the format of dimension: [700,800]
     123             :   /// ratio: 2:3 , sub-region: [700,800,x0.50,y0.60],
     124             :   /// or offset :[ 700,800,offset-x0.65,offset-y0.80]
     125             :   /// For more details, Read documentation:
     126             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#canvas
     127             :   ///
     128             :   /// Example:  Canvas by width & Height:
     129             :   ///
     130             :   /// ```dart
     131           1 :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     132             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     133             :   /// final response =  imageTransformation.canvas('700,800');
     134           3 :   /// ```
     135             :   ///
     136             :   /// Example:  Canvas by ratio:
     137           3 :   ///
     138             :   /// ```dart
     139             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     140           2 :   /// final imageTransformation = stack.imageTransform(imageUrl);
     141             :   /// final response =  imageTransformation.canvas('2:3');
     142             :   /// ```
     143             :   ///
     144           1 :   /// Example:  Canvas  Sub-region:
     145             :   ///
     146             :   /// ```dart
     147             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     148           2 :   /// final imageTransformation = stack.imageTransform(imageUrl);
     149             :   /// final response =  imageTransformation.canvas('700,800,x0.50,y0.60');
     150             :   /// ```
     151             :   ///
     152             :   /// Example:  Canvas and offset:
     153             :   ///
     154             :   /// ```dart
     155             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     156             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     157             :   /// final response =  imageTransformation.
     158             :   ///                   canvas('700,800,offset-x0.65,offset-y0.80');
     159             :   /// ```
     160             :   ///
     161             :   void canvas(String canvasValue) {
     162             :     query.append('canvas', canvasValue);
     163             :   }
     164             : 
     165             :   /// The contrast parameter allows you to increase or decrease
     166             :   /// the difference between the darkest and lightest tones in a given image.
     167             :   /// To specify contrast for an image, use a whole number (integer)
     168             :   /// between -100 and 100. You can also define contrast
     169             :   /// using any decimal number between -100.00 and 100.00.
     170             :   ///
     171             :   /// To increase the value of the contrast parameter of an
     172             :   /// image, pass a positive value or negative value
     173             :   /// For more details, Read documentation:
     174             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#contrast
     175             :   ///
     176             :   /// Example
     177             :   ///
     178             :   /// ```dart
     179             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     180             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     181             :   /// final response = await imageTransformation.contrast(20);
     182             :   /// ```
     183             : 
     184             :   void contrast(int contrast) {
     185             :     query.append('contrast', contrast.toString());
     186             :   }
     187             : 
     188             :   /// The format function lets you converts a given image
     189             :   /// from one format to another.
     190             :   /// The formats that the source image can be converted
     191             :   /// to are gif, png, jpg (for JPEG),
     192           1 :   /// pjpg (for Progressive JPEG), webp, webpll (Lossless), and webply (Lossy).
     193             :   ///
     194             :   /// for more details read documentation:
     195             :   /// For more details, Read documentation:
     196           1 :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#convert-formats
     197             :   ///
     198           1 :   ///  Example:
     199             :   ///
     200             :   /// ```dart
     201           1 :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     202             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     203             :   /// final response = await imageTransformation.convert(Format.pjpg).fetch();
     204           0 :   /// ```
     205             :   void convert(Format format) {
     206             :     format.when(gif: (formatResult) {
     207           0 :       query.append('format', 'gif');
     208             :     }, png: (formatResult) {
     209           1 :       query.append('format', 'png');
     210           2 :     }, jpg: (formatResult) {
     211             :       query.append('format', 'jpg');
     212             :     }, pjpg: (formatResult) {
     213             :       query.append('format', 'pjpg');
     214             :     }, webp: (formatResult) {
     215             :       query.append('format', 'webp');
     216             :     }, webplossy: (formatResult) {
     217             :       query.append('format', 'webply');
     218             :     }, webplossless: (formatResult) {
     219             :       query.append('format', 'webpll');
     220             :     });
     221             :   }
     222             : 
     223             :   void crop(String cropValue) {
     224             :     // checks if cropRatio is not null then takes height,
     225             :     // width and cropRatio as prams
     226             :     // else it takes crop params and comas separated width & height
     227             :     query.append('crop', cropValue);
     228             :   }
     229             : 
     230             :   /// The crop function allows you to remove pixels from an image.
     231             :   /// You can crop an image by specifying the height and width in
     232             :   /// pixels or percentage value, or defining height and width in aspect ratio.
     233           1 :   /// You can also define a sub region (i.e., define
     234             :   /// the starting point for crop)
     235           3 :   /// before cropping the image, or you can offset the image on its
     236             :   /// X and Y axis (i.e., define the centre point of the crop)
     237             :   /// before cropping the image.
     238           3 : 
     239             :   /// You can set the X-axis and Y-axis position of the
     240             :   /// top left corner of the crop by
     241             :   /// using the query ?crop={width_value},{height_value},x{value},y{value}.
     242           2 :   /// This lets you define the starting point of the crop region.
     243           2 :   /// The x-axis value and y-axis value can be defined in pixels or percentage.
     244           1 :   ///
     245           2 :   /// An `example` of this would be
     246             :   /// ?crop=300,400,x150,y75 or ?crop=300,400,x0.50,y0.60.
     247             :   /// Compulsory parameters [width] and [height]
     248             :   /// Optional parameters: [region]
     249             :   /// Optional parameters: [offset]
     250             :   /// For more details, Read documentation:
     251             :   /// For more details read the doc: https://www.contentstack.com/docs/developers/apis/image-delivery-api/#crop-images
     252             :   ///
     253             :   /// Example: With Aspect Ratio:
     254             :   ///
     255             :   /// ```dart
     256             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     257             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     258             :   /// final response = await imageTransformation.
     259             :   ///                   cropBy(150, 100, cropRatio: '1:3').fetch();
     260             :   /// log.fine(response);
     261             :   /// ```
     262             :   ///
     263             :   /// Example: Without aspect Ratio:
     264             :   ///
     265             :   /// ```dart
     266             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     267             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     268             :   /// final response = await imageTransformation.cropBy(150, 100).fetch();
     269           1 :   /// log.fine(response);
     270           1 :   /// ```
     271             :   void cropBy(int width, int height, {String region, String offset}) {
     272           1 :     /// checks if cropRatio is not null then takes height, width and
     273             :     /// cropRatio as prams else it takes crop params and comas
     274             :     /// separated width & height
     275           1 :     final cropLRBL = [];
     276             :     if (width != null) {
     277             :       cropLRBL.add(width);
     278           1 :     }
     279             :     if (height != null) {
     280             :       cropLRBL.add(height);
     281           1 :     }
     282             :     if (region != null) {
     283           1 :       cropLRBL.add(region);
     284           2 :     }
     285             :     if (offset != null) {
     286             :       cropLRBL.add(offset);
     287             :     }
     288             :     final commaSeparated = cropLRBL.join(', ');
     289             :     query.append('crop', commaSeparated);
     290             :   }
     291             : 
     292             :   ///To implement the device pixel ratio functionality of the
     293             :   ///Image Delivery API, you require two parameters "dpr" and "height or width".
     294             :   ///For more details read the documentation:
     295             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#set-device-pixel-ratio
     296             :   ///
     297             :   /// For more details, Read documentation:
     298             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#dpr
     299             :   ///
     300             :   /// Example
     301             :   ///
     302             :   /// ```dart
     303             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     304             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     305             :   /// final response = await imageTransformation.dpr(30, 60, 12).fetch();
     306             :   /// ```
     307           1 :   ///
     308             :   void dpr(int dpr) {
     309             :     query.append('dpr', dpr.toString());
     310             :   }
     311             : 
     312             :   ///Makes API Request of respective function.
     313             :   Future<T> fetch<T, K>() async {
     314             :     final bool _validURL = Uri.parse(_imageUrl).isAbsolute;
     315             :     if (!_validURL) {
     316             :       throw Exception('Invalid url requested');
     317           2 :     }
     318           2 :     final response = await client.get(getUrl());
     319           1 :     if (response.statusCode == 200) {
     320           2 :       final Map bodyJson = jsonDecode(response.body);
     321           1 :       if (T == AssetModel && bodyJson.containsKey('asset')) {
     322           2 :         return AssetModel.fromJson(bodyJson['asset']) as T;
     323           1 :       } else {
     324           2 :         return json.decode(response.body);
     325           1 :       }
     326           2 :     } else {
     327           1 :       return json.decode(response.body);
     328           2 :     }
     329           1 :   }
     330           2 : 
     331           1 :   /// This parameter enables you to fit the given image
     332           2 :   /// properly within the specified height and width.
     333             :   /// You need to provide values for the height, width and fit parameters.
     334             :   /// The two available values for the fit parameter are bounds and crop.
     335             :   /// fit accepts optional parameters [width], [height]
     336             :   /// of type [int] and fir of type [Fit]
     337             :   ///
     338             :   /// For more details, Read documentation:
     339             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#fit-mode
     340             :   ///
     341             :   /// Example:
     342             :   ///
     343             :   /// ```dart
     344             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     345             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     346             :   /// final response = await imageTransformation.
     347             :   ///                  fitBy(  250,  250, Fit.crop).fetch();
     348             :   /// ```
     349             :   ///
     350             : 
     351             :   void fit(double width, double height, Fit fit) {
     352             :     if (width != null) {
     353             :       query.append('width', width.toString());
     354             :     }
     355             :     if (height != null) {
     356             :       query.append('height', height.toString());
     357             :     }
     358             :     if (fit != null) {
     359             :       //enum Fit { bounds, crop }
     360           1 :       fit.when(bounds: (value) {
     361             :         query.append('fit', 'bounds');
     362             :       }, crop: (value) {
     363             :         query.append('fit', 'crop');
     364             :       });
     365           2 :     }
     366             :   }
     367             : 
     368           2 :   /// The frame parameter fetches the first frame from an animated GIF
     369             :   /// (Graphics Interchange Format) file that comprises
     370             :   /// a sequence of moving images. For more details, Read documentation:
     371           2 :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#frame
     372             :   ///
     373             :   /// Example:
     374           2 :   ///
     375             :   /// ```dart
     376             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     377           2 :   /// final imageTransformation = stack.imageTransform(imageUrl);
     378             :   /// final response = await imageTransformation.frame(30).fetch();
     379             :   /// ```
     380             :   ///
     381             :   void frame(int frame) {
     382             :     query.append('frame', frame.toString());
     383             :   }
     384             : 
     385             :   String getUrl() {
     386             :     return query.toUrl(_imageUrl);
     387             :   }
     388             : 
     389             :   ///The orient parameter lets you control the cardinal
     390             :   ///orientation of the given image. Using this parameter, you can orient
     391             :   ///the image right or left, flip horizontally
     392             :   ///or vertically or both, and do a lot more. It can automatically correct the
     393             :   ///orientation of the image if the source image contains orientation details
     394             :   ///within its EXIF data (Exchangeable Image File Format).
     395             :   ///
     396             :   ///[orient] parameter should be enum type of  [Orientation]
     397             :   ///
     398             :   /// For more details, Read documentation:
     399             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#reorient-images
     400             :   ///
     401             :   ///  Example:
     402           1 :   ///
     403           2 :   /// ```dart
     404             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     405             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     406             :   /// final response = await imageTransformation
     407             :   ///                  .orientation(Orientation.vertically).fetch();
     408             :   /// ```
     409             :   void orientation(Orientation orient) {
     410             :     //  toDefault = '1';
     411             :     //  horizontally = '2';
     412             :     //  horizontallyAndVertically = '3';
     413             :     //  vertically = '4';
     414             :     //  horizontallyAndRotate90DegreeLeft = '5';
     415             :     //  degrees90TowardsRight = '6';
     416             :     //  horizontallyAndRotate90DegreesRight = '7';
     417             :     //  rotate90DegreesLeft = '8';
     418             :     if (orient != null) {
     419           1 :       orient.when(toDefault: (orientation) {
     420           2 :         query.append('orient', 1);
     421             :       }, horizontally: (orientation) {
     422             :         query.append('orient', 2);
     423             :       }, horizontallyAndVertically: (orientation) {
     424             :         query.append('orient', 3);
     425             :       }, vertically: (orientation) {
     426             :         query.append('orient', 4);
     427             :       }, horizontallyAndRotate90DegreeLeft: (orientation) {
     428             :         query.append('orient', 5);
     429             :       }, degrees90TowardsRight: (orientation) {
     430             :         query.append('orient', 6);
     431             :       }, horizontallyAndRotate90DegreesRight: (orientation) {
     432             :         query.append('orient', 7);
     433             :       }, rotate90DegreesLeft: (orientation) {
     434             :         query.append('orient', 8);
     435             :       });
     436             :     }
     437             :   }
     438             : 
     439             :   /// The overlay parameter allows you to put one image on top of another.
     440           1 :   /// You need to specify the relative URL of the image as
     441           2 :   /// value for this parameter.
     442             :   /// By default, the cropping alignment will be middle,
     443             :   /// center. See overlay-align for more details.
     444             :   /// It accepts [overlayUrl]  as a parameter to put one
     445             :   /// [overlayUrl] on top of [_imageUrl]
     446             :   /// There are optional params also like [overlayAlign],
     447             :   /// [overlayRepeat], [overlayWidth], [overlayHeight]
     448             :   /// Fr more details read the documentation:
     449             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#overlay
     450             :   ///
     451             :   /// For more details, Read documentation:
     452             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#overlay-pad
     453             :   ///
     454             :   /// Example
     455             :   /// ```dart
     456             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     457             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     458             :   /// final response = await imageTransformation.
     459             :   ///                   overlay('overlayUrl', overlayWidth: '').fetch();
     460           1 :   /// ```
     461           3 :   ///
     462             :   void overlay(String overlayUrl,
     463             :       {String overlayAlign,
     464             :       String overlayRepeat,
     465             :       int overlayWidth,
     466             :       int overlayHeight}) {
     467             :     query.append('overlay', overlayUrl);
     468             : 
     469             :     if (overlayAlign != null) {
     470             :       query.append('overlay-align', overlayAlign);
     471             :     }
     472             :     if (overlayRepeat != null) {
     473             :       query.append('overlay-repeat', overlayRepeat);
     474             :     }
     475             :     if (overlayWidth != null) {
     476             :       query.append('overlay-width', overlayWidth);
     477             :     }
     478             :     if (overlayHeight != null) {
     479             :       query.append('overlay-height', overlayHeight);
     480             :     }
     481           1 :   }
     482           3 : 
     483             :   /// You can either specify all the four padding
     484             :   /// values (top, right, bottom, and left)
     485             :   /// or combine two or more values
     486             :   //  top, right, bottom, left
     487             :   ///
     488             :   /// Example:
     489             :   ///
     490             :   /// ```dart
     491             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     492             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     493             :   /// final response = await imageTransformation.
     494             :   ///                         addPadding("25,50,75,100").fetch();
     495             :   /// ```
     496             :   void overlayPadding(String overlayPadding) {
     497             :     query.append('overlay-pad', overlayPadding);
     498           1 :   }
     499           3 : 
     500             :   /// This function lets you add extra pixels to the edges of an image.
     501             :   /// This is useful if you want to add whitespace or border to an image.
     502             :   /// The value for this parameter can be given in pixels or percentage.
     503             :   ///
     504             :   /// You can specify values for top, right, bottom, and left
     505             :   /// padding for an image.
     506             :   /// For example, to add padding to the top edge by 25px,
     507             :   /// right edge by 50px, bottom edge by 75px and left edge by 100,
     508             :   ///
     509             :   /// For more details, Read documentation:
     510             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#pad
     511             :   ///
     512             :   ///Example:
     513             :   ///
     514             :   /// ```dart
     515             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     516           1 :   /// final imageTransformation = stack.imageTransform(imageUrl);
     517           3 :   /// final response = await imageTransformation.
     518             :   ///                        padding("25,50,75,100").fetch();
     519             :   /// ```
     520             :   ///
     521             :   void padding(String padding) {
     522             :     query.append('pad', padding);
     523             :   }
     524             : 
     525             :   /// The quality function lets you control the compression level of
     526             :   /// images that have Lossy file format.
     527             :   /// The value for this parameters can be entered
     528             :   /// in any whole number (taken as a percentage)
     529             :   /// between 1 and 100. The lower the number, the smaller
     530             :   /// will be file size and lower quality, and vice versa.
     531             :   /// If the source image file is not of Lossy file format,
     532             :   /// this parameter will be ignored.
     533             :   ///
     534             :   /// For more details, Read documentation:
     535             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#quality
     536           1 :   ///
     537           3 :   /// Example:
     538             :   ///
     539             :   /// ```dart
     540             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     541             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     542             :   /// final response = await imageTransformation.quality(2).fetch();
     543             :   /// ```
     544             :   ///
     545             :   void quality(int quality) {
     546             :     query.append('quality', quality.toString());
     547             :   }
     548             : 
     549             :   /// this function lets you dynamically resize the
     550             :   /// width of the output image by specifying pixels or percentage values
     551             :   /// for more details read documentation:
     552             :   /// The disable function disables the functionality
     553             :   /// that is enabled by default. For instance, upscale is always
     554             :   /// enabled, in which the image is upscaled
     555             :   /// if the output image (by specifying the width or height)
     556             :   /// is bigger than the source image.
     557             :   /// To disable this feature, you can use the query ?disable=upscale.
     558             :   /// This ensures that even if the specified height or width
     559           1 :   /// is much bigger than the actual image,
     560           3 :   /// it will not be rendered disproportionately.
     561             :   ///
     562             :   /// For more details, Read documentation:
     563             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#resize-images
     564             :   ///
     565             :   /// Example:
     566             :   ///
     567             :   /// ```dart
     568             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     569             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     570             :   /// final response =
     571             :   ///       await imageTransformation.resize(width:100,disable:true).fetch();
     572             :   /// ```
     573             :   void resize({int width, int height, bool disable}) {
     574             :     if (width != null) {
     575             :       //queryParameter['width'] = width.toString();
     576             :       query.append('width', width.toString());
     577             :     }
     578             :     if (height != null) {
     579             :       query.append('height', height.toString());
     580             :     }
     581           1 :     if (disable != null && disable) {
     582           3 :       query.append('disable', 'upscale');
     583             :     }
     584             :   }
     585             : 
     586             :   ///
     587             :   /// The resize-filter parameter allows you to use the resizing
     588             :   /// filter to increase or decrease the number of pixels in a given image.
     589             :   /// This parameter resizes the given image without adding or
     590             :   /// removing any data from it.
     591             :   ///
     592             :   /// The following values are acceptable for the resize-filter parameter
     593             :   /// For more details, Read documentation:
     594             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#resize-filter
     595             : 
     596             :   /// Example:
     597             :   ///
     598             :   /// ```dart
     599             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     600             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     601             :   /// final response =  imageTransformation.
     602             :   ///       resizeFilter(width: 20, height: 40, filter: Filter.bilinear);
     603             :   /// ```
     604           1 :   ///
     605             :   void resizeFilter({int width, int height, Filter filter}) {
     606           3 :     if (width != null) {
     607             :       query.append('width', width.toString());
     608             :     }
     609           3 :     if (height != null) {
     610             :       query.append('height', height.toString());
     611             :     }
     612           2 :     if (filter != null) {
     613           2 :       filter.when(nearest: (filterType) {
     614           1 :         query.append('resize-filter', 'nearest');
     615           2 :       }, bilinear: (filterType) {
     616           1 :         query.append('resize-filter', 'bilinear');
     617           2 :       }, bicubic: (filterType) {
     618           1 :         query.append('resize-filter', 'bicubic');
     619           2 :       }, lanczos: (filterType) {
     620             :         query.append('resize-filter', 'lanczos3');
     621             :       });
     622             :     }
     623             :   }
     624             : 
     625             :   /// The saturation parameter allows you to increase or decrease the intensity
     626             :   /// of the colors in a given image. To specify the saturation
     627             :   /// for an image, use a whole number (integer) between -100 and 100.
     628             :   /// You can also define saturation using any decimal
     629             :   /// number between -100.00 and 100.00
     630             :   /// For more details, Read documentation:
     631             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#saturation
     632             :   ///
     633             :   /// Example:
     634             :   ///
     635             :   /// ```dart
     636             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     637             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     638             :   /// final response = await imageTransformation.saturation(20);
     639             :   /// ```
     640             : 
     641             :   void saturation(int saturation) {
     642             :     query.append('saturation', saturation.toString());
     643             :   }
     644             : 
     645             :   /// The frame parameter fetches the first frame from an animated GIF
     646             :   /// (Graphics Interchange Format) file that comprises a sequence
     647             :   /// of moving images. increase the sharpness of a given image by amount,
     648             :   /// radius and threshold For more details, Read documentation:
     649             :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#sharpen
     650             :   ///
     651             :   /// Example:
     652             :   ///
     653             :   /// ```dart
     654             :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     655             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     656             :   /// final response = await imageTransformation.sharpen(5, 1000, 2').fetch();
     657             :   /// ```
     658             :   ///
     659             :   void sharpen(int amount, int radius, int threshold) {
     660             :     query.append('sharpen', 'a$amount,r$radius,t$threshold');
     661             :   }
     662             : 
     663             :   ///The trim parameter lets you trim an image from the edges.
     664             :   ///This is especially useful for removing border or white spaces
     665             :   ///that the downloaded images usually come with.
     666             :   ///The value for this parameter can be given in pixels or percentage.
     667             :   ///You can specify values for [top], [right], [bottom], and [left]
     668             :   ///edges of an image. For example, to trim the top edge by 25px, right edge
     669             :   ///by 50px, bottom edge by 75px and left edge by 100
     670             :   /// provide [trim] as comma separated value like, 25,50,75,100
     671             :   ///
     672           1 :   /// For more details, Read documentation:
     673           2 :   /// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#trim-images
     674             :   ///
     675             :   /// Example:
     676             :   ///
     677           1 :   /// ```dart
     678           3 :   /// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
     679             :   /// final imageTransformation = stack.imageTransform(imageUrl);
     680           0 :   /// final response = await imageTransformation.trim(25).fetch();
     681             :   /// ```
     682           4 :   void trim([int top, int right, int bottom, int left]) {
     683           2 :     final trimLRBL = [];
     684           0 :     if (top != null) {
     685           0 :       trimLRBL.add(top);
     686           0 :     }
     687             :     if (right != null) {
     688           0 :       trimLRBL.add(top);
     689             :     }
     690             :     if (bottom != null) {
     691           2 :       trimLRBL.add(bottom);
     692             :     }
     693             :     if (left != null) {
     694             :       trimLRBL.add(left);
     695           1 :     }
     696           3 :     final joinedValue = trimLRBL.join(', ');
     697             :     query.append('trim', joinedValue);
     698             :   }
     699             : }

Generated by: LCOV version 1.15