image_compress

Last updated:

0 purchases

image_compress Image
image_compress Images
Add to Cart

Description:

image compress

Package Flutter for compress and watermark image native #

Link url flutter : https://pub.dev/packages/image_compress


How to use : #
Simple Function #

Default compress maximal width : 1280, maximal height : 960, desire quality : 100

await ImageCompress.compress(imageSrc: imageFile!.path);
copied to clipboard
Custom Compress Image No Watermark Function #
await ImageCompress.compress(imageSrc: imageFile!.path,
desiredQuality: 90,
maxWidth: 1280,
maxHeight: 1080,

);
copied to clipboard
Add Watermark and Datestamp Function #

Watermark Only :

await ImageCompress.compress(imageSrc: imageFile!.path,
watermarkText: 'Test lorem ipsum',
);
copied to clipboard

Watermark with datestamp :

await ImageCompress.compress(imageSrc: imageFile!.path,
watermarkText: 'Test lorem ipsum',
isDateWatermark: true,
);
copied to clipboard
Complete Code #
import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:image_compress/image_compress.dart';
import 'package:image_picker/image_picker.dart';

Future<Null> main() async {
runApp(new MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
File? imageFile;

final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

@override
initState() {
super.initState();
}

Future compressNow(ImageSource imageSource) async {
XFile? img = await ImagePicker().pickImage(source: imageSource,
imageQuality: 100, preferredCameraDevice: CameraDevice.front);
//Source of the image in _futureImage
imageFile = File(img!.path);
print("FILE SIZE BEFORE: " + imageFile!.lengthSync().toString());
await ImageCompress.compress(imageSrc: imageFile!.path,
desiredQuality: 90,
watermarkText: 'Test lorem ipsum',
maxWidth: 1280,
maxHeight: 1080,

); //desiredQuality ranges from 0 to 100
print("FILE SIZE AFTER: " + imageFile!.lengthSync().toString());


setState(() {
imageFile;
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Compress Image Example App'),
),
body: Center(
child: imageFile == null
? const Text('No image selected.')
: Image.file(imageFile!),
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
FloatingActionButton(
onPressed: () {
compressNow(ImageSource.gallery);
},
tooltip: 'Pick Image',
child: const Icon(Icons.photo),
),
const SizedBox(height: 10,),
FloatingActionButton(
onPressed: () {
compressNow(ImageSource.camera);
},
tooltip: 'Pick Image',
child: const Icon(Icons.add_a_photo),
),
],
),
),
);
}

void showInSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
}


String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();

}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.