https://github.com/imgeng/imageengine-helpers-dart
https://github.com/imgeng/imageengine-helpers-dart
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/imgeng/imageengine-helpers-dart
- Owner: imgeng
- License: mit
- Created: 2024-08-06T08:45:04.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-02-15T01:51:39.000Z (3 months ago)
- Last Synced: 2025-02-15T02:30:15.629Z (3 months ago)
- Language: Dart
- Size: 177 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Dart ImageEngine Helpers
A tiny set of helpers and Dart types for building [ImageEngine](https://imageengine.io) query URLs for your distribution.
These utilities are useful if you want to use an object to declare your [directives](https://support.imageengine.io/hc/en-us/articles/360058880672-directives) when retrieving assets from an ImageEngine distribution.
### Installation
Add this package to your `pubspec.yaml` dependencies:
```yaml
dependencies:
imageengine_helpers: ^1.0.0
```Then run:
```bash
flutter pub get
```### Types:
```dart
enum IEFormat {
png,
gif,
jpg,
bmp,
webp,
jp2,
svg,
mp4,
jxr,
avif,
jxl,
}enum IEFit {
stretch,
box,
letterbox,
cropbox,
outside,
}class IEDirectives {
final int? width; // the intrinsic width of the final image
final int? height; // the intrinsic height of the final image
final int? autoWidthFallback; // if WURFL device detection should be tried with a fallback value in case it failsfinal int? scaleToScreenWidth; // 0-100 float
final String? crop; // a string representation like "width,height,left,top"final IEFormat? format; // the output format
final IEFit? fit; // the image fit in relation to the provided width/heightfinal int? compression; // 0-100
final int? sharpness; // 0-100
final int? rotate; // -360-360final bool? inline; // convert image to dataURL
final bool? keepMeta; // keep EXIF image data
final bool? noOptimization; // don't apply IE optimizations
final bool? forceDownload; // force download
final double? maxDevicePixelRatio; // 1-4 floatIEDirectives({
this.width,
this.height,
this.autoWidthFallback,
this.scaleToScreenWidth,
this.crop,
this.format,
this.fit,
this.compression,
this.sharpness,
this.rotate,
this.inline,
this.keepMeta,
this.noOptimization,
this.forceDownload,
this.maxDevicePixelRatio,
});
}
```### Example Usage
```dart
import 'package:imageengine_helpers/imageengine_helpers.dart';void main() {
IEDirectives directives = IEDirectives(
width: 400,
height: 200,
fit: IEFit.cropbox,
compression: 10,
inline: true,
format: IEFormat.png,
forceDownload: true,
maxDevicePixelRatio: 2.1,
);String sourceUrl = "https://my_ie_distribution.imgeng.io/path/to_asset1.jpg";
String finalUrl = buildIEUrl(sourceUrl, directives);
print(finalUrl);
// Outputs: "https://my_ie_distribution.imgeng.io/path/to_asset1.jpg?imgeng=/w_400/h_200/m_cropbox/cmpr_10/in_true/f_png/dl_true"String directivesString = buildIEDirectives(directives);
print(directivesString);
// Outputs: "/w_400/h_200/m_cropbox/cmpr_10/in_true/f_png/dl_true"String queryString = buildIEQueryString(directives);
print(queryString);
// Outputs: "?imgeng=/w_400/h_200/m_cropbox/cmpr_10/in_true/f_png/dl_true"
}
```