Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Update #4

Merged
merged 10 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.4
## 0.0.5

Customized text size of watermark
Change in the way of doing things
57 changes: 57 additions & 0 deletions README-es.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# image_watermark

## Idiomas:
[![English](https://img.shields.io/badge/Language-English-blueviolet?style=for-the-badge)](README.md)


Image watermark es un paquete de flutter para agregar a cualquier imagen textos u otras imágenes como marcas de agua, puedes personalizar la posición de la marca de agua y el color. Basado en el paquete [Image](https://pub.dev/packages/image/).\
Publicación del paquete: https://pub.dev/packages/image_watermark

## Código de Ejemplo
Agrega texto en el centro de la Imagen como marca de agua, los parametros son la imagen convertida a Uint8List y el texto (String), se retorna una imagen en Uint8List
```dart
final watermarkedImg = await ImageWatermark.addTextWatermarkCentered(
imgBytes: imgBytes,
watermarktext: 'watermarkText',
);
```

```dart
final watermarkedImgBytes = await ImageWatermark.addTextWatermarkCentered(
imgBytes: imgBytes, ///Imagen en Uint8List
watermarktext: 'watermarkText', ///texto marca de agua
color: Colors.white, ///default : Colors.black
);
```
Cambia la posición de la marca de agua
```dart
final watermarkedImg = await ImageWatermark.addTextWatermark(
imgBytes: imgBytes, ///Imagen en Uint8List
watermarktext: 'watermarkText', ///texto marca de agua
dstX: 20, ///posición de la marca de agua (coordenadas de X)
dstY: 30, ///posición de la marca de agua (coordenadas de Y)
color: Colors.green, ///default : Colors.black
)
```
Agrega una Imagen como marca de agua en otra Imagen
```dart
final watermarkedImgBytes = await ImageWatermark.addImageWatermark(
originalImageBytes: imgBytes,
waterkmarkImageBytes: watermarkImgByte,
);
```

```dart
final watermarkedImgBytes = await ImageWatermark.addImageWatermark(
originalImageBytes: imgBytes, ///Imagen Principal en Uint8List
waterkmarkImageBytes: imgBytes2, ///Imagen marca de agua en Uint8List
imgHeight: 200, ///Altura de la imagen marca de agua
imgWidth: 200, ///Anchura de la imagen marca de agua
dstY: 400, ///posición de la marca de agua (coordenadas de Y)
dstX: 400, ///posición de la marca de agua (coordenadas de X)
);
```

<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot1.png" height="400">
<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot2.png" height="400">
<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot3.png" height="400">
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
# image_watermark

## Languages:
[![Spanish](https://img.shields.io/badge/Language-Spanish-blueviolet?style=for-the-badge)](README-es.md)


Image watermark is flutter pacakge to add text watermark and image watermark on image,you can customize the position of watermark and color.
Based on [Image](https://pub.dev/packages/image/) pacakge.\
Check on pub.dev: https://pub.dev/packages/image_watermark

## Example code
Add watermark text at center of image,parameter image bytes and string and it returns image bytes
```dart
var watermarkedImg = await image_watermark.addTextWatermarkCentered(imgBytes,'watermarkText');
final watermarkedImg = await ImageWatermark.addTextWatermarkCentered(
imgBytes: imgBytes,
watermarktext: 'watermarkText',
);
```

```dart
var watermarkedImgBytes = await image_watermark.addTextWatermarkCentered(
imgBytes, ///image bytes
watermarkText, ///watermark text
color: Colors.black, ///default : Colors.white
final watermarkedImgBytes = await ImageWatermark.addTextWatermarkCentered(
imgBytes: imgBytes, ///image bytes
watermarktext: 'watermarkText', ///watermark text
color: Colors.white, ///default : Colors.black
);
```
Change the position of watermark
```dart
var watermarkedImg = await image_watermark.addTextWatermark(
imgBytes, ///image bytes
'watermarkText', ///watermark text
20, ///position of watermark x coordinate
30, ///y coordinate
color: Colors.green, ///default : Colors.white
final watermarkedImg = await ImageWatermark.addTextWatermark(
imgBytes: imgBytes, ///image bytes
watermarktext: 'watermarkText', ///watermark text
dstX: 20, ///position of watermark x coordinate
dstY: 30, ///y coordinate
color: Colors.green, ///default : Colors.black
)
```
Add image as watermark on image
```dart
watermarkedImgBytes = await image_watermark.addImageWatermark(imgBytes,watermarkImgByte);
final watermarkedImgBytes = await ImageWatermark.addImageWatermark(
originalImageBytes: imgBytes,
waterkmarkImageBytes: watermarkImgByte,
);
```

```dart
watermarkedImgBytes = await image_watermark.addImageWatermark(
imgBytes, //image bytes
imgBytes2,//watermark img bytes
final watermarkedImgBytes = await ImageWatermark.addImageWatermark(
originalImageBytes: imgBytes, //image bytes
waterkmarkImageBytes: imgBytes2, //watermark img bytes
imgHeight: 200, //watermark img height
imgWidth: 200, //watermark img width
dstY: 400,
dstX: 400);
dstX: 400,
);
```

<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot1.png" height="400">
<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot2.png" height="400">
<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot3.png" height="400">
<img src="https://raw.githubusercontent.com/saurabh-m-w/image_watermark/main/screenshots/screenshot3.png" height="400">
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
97 changes: 49 additions & 48 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image_watermark/image_watermark.dart';
//import 'package:example/image_watermark.dart';

void main() {
runApp(const MyApp());
Expand All @@ -19,7 +18,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(),
home: const HomeScreen(),
);
}
}
Expand All @@ -28,21 +27,21 @@ class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);

@override
_HomeScreenState createState() => _HomeScreenState();
HomeScreenState createState() => HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
final ImagePicker _picker = ImagePicker();
var imgBytes;
var imgBytes2;
var _image;
var watermarkedImgBytes;
class HomeScreenState extends State<HomeScreen> {
final _picker = ImagePicker();
Uint8List? imgBytes;
Uint8List? imgBytes2;
XFile? _image;
Uint8List? watermarkedImgBytes;
bool isLoading = false;
String watermarkText = "", imgname = "image not selected";
List<bool> textOrImage = [true, false];

pickImage() async {
XFile? image = await _picker.pickImage(
final image = await _picker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
Expand Down Expand Up @@ -70,80 +69,81 @@ class _HomeScreenState extends State<HomeScreen> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('image_watermark'),
title: const Text('image_watermark'),
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Center(
child: Container(
child: SizedBox(
width: 600,
child: Column(
children: [
GestureDetector(
onTap: pickImage,
child: Container(
margin: EdgeInsets.all(15),
margin: const EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(Radius.circular(5))),
borderRadius:
const BorderRadius.all(Radius.circular(5))),
width: 600,
height: 250,
child: _image == null
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: const [
Icon(Icons.add_a_photo),
SizedBox(
height: 10,
),
Text('Click here to choose image')
],
)
: Image.memory(imgBytes,
: Image.memory(imgBytes!,
width: 600, height: 200, fit: BoxFit.fitHeight)),
),
ToggleButtons(
fillColor: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(8)),
borderRadius: const BorderRadius.all(Radius.circular(8)),
borderWidth: 3,
borderColor: Colors.black26,
selectedBorderColor: Colors.black54,
selectedColor: Colors.black,
children: [
onPressed: (index) {
textOrImage = [false, false];
setState(() {
textOrImage[index] = true;
});
},
isSelected: textOrImage,
children: const [
Padding(
padding: const EdgeInsets.all(8.0),
padding: EdgeInsets.all(8.0),
child: Text(
' Text ',
),
),
// second toggle button
Padding(
padding: const EdgeInsets.all(8.0),
padding: EdgeInsets.all(8.0),
child: Text(
' Image ',
))
],
onPressed: (index) {
textOrImage = [false, false];
setState(() {
textOrImage[index] = true;
});
},
isSelected: textOrImage,
),
SizedBox(
const SizedBox(
height: 10,
),
textOrImage[0]
? Padding(
padding: EdgeInsets.all(15),
child: Container(
padding: const EdgeInsets.all(15),
child: SizedBox(
width: 600,
child: TextField(
onChanged: (val) {
watermarkText = val;
},
decoration: InputDecoration(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Watermark Text',
hintText: 'Watermark Text',
Expand All @@ -155,11 +155,11 @@ class _HomeScreenState extends State<HomeScreen> {
children: [
ElevatedButton(
onPressed: pickImage2,
child: Text('Select Watermark image')),
child: const Text('Select Watermark image')),
Text(imgname)
],
),
SizedBox(
const SizedBox(
height: 10,
),
ElevatedButton(
Expand All @@ -169,22 +169,23 @@ class _HomeScreenState extends State<HomeScreen> {
});
if (textOrImage[0]) {
watermarkedImgBytes =
await image_watermark.addTextWatermark(
imgBytes,

await ImageWatermark.addTextWatermark(
///image bytes
watermarkText, //watermark text
20, //
30,
color: Colors.black, //default : Colors.white
imgBytes: imgBytes!,

///watermark text
watermarkText: watermarkText,
dstX: 20,
dstY: 30,
);

/// default : imageWidth/2
} else {
watermarkedImgBytes =
await image_watermark.addImageWatermark(
imgBytes, //image bytes
imgBytes2,
await ImageWatermark.addImageWatermark(
//image bytes
originalImageBytes: imgBytes!,
waterkmarkImageBytes: imgBytes2!,
imgHeight: 200,
imgWidth: 200,
dstY: 400,
Expand All @@ -195,15 +196,15 @@ class _HomeScreenState extends State<HomeScreen> {
isLoading = false;
});
},
child: Text('Add Watermark'),
child: const Text('Add Watermark'),
),
SizedBox(
const SizedBox(
height: 10,
),
isLoading ? CircularProgressIndicator() : Container(),
isLoading ? const CircularProgressIndicator() : Container(),
watermarkedImgBytes == null
? Container()
: Image.memory(watermarkedImgBytes),
? const SizedBox()
: Image.memory(watermarkedImgBytes!),
],
),
),
Expand Down