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

Generated by: LCOV version 1.15