Skip to content

Commit

Permalink
feat(stickers): flag to not serialize stickers (#306)
Browse files Browse the repository at this point in the history
* feat(stickers): flag to not serialize stickers

* chore(release): bump version to 7.2.0

docs: improve doc comments for export_state_history and configs

---------

Co-authored-by: hm21 <[email protected]>
  • Loading branch information
saif-ellafi and hm21 authored Jan 2, 2025
1 parent 5fb80e2 commit 60d9c7f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 7.2.0
- **FEAT**(export-history): Introduce the `serializeSticker` parameter to `ExportEditorConfigs` to enable exporting only `StickerLayerData` without converting the sticker to a `Uint8List`. This change incorporates the updates from pull request [#306](https://github.com/hm21/pro_image_editor/pull/306).

## 7.1.1
- **FIX**(android): Resolve crop-drag conflicts with navigation gestures on android. This resolves issue [#303](https://github.com/hm21/pro_image_editor/issues/303)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ The state history from the image editor can be exported and imported. However, i
exportFilter: true,
exportEmoji: true,
exportSticker: true,
serializeSticker: true,
historySpan: ExportHistorySpan.all,
),
).toJson(); // or => toMap(), toFile()
Expand Down
34 changes: 20 additions & 14 deletions lib/models/import_export/export_state_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,26 @@ class ExportStateHistory {
layer.runtimeType == StickerLayerData) {
layers.add((layer as StickerLayerData).toStickerMap(stickers.length));

double imageWidth = editorConfigs.stickerEditor.initWidth * layer.scale;
Size targetSize = Size(
imageWidth,
MediaQuery.of(context).size.height /
MediaQuery.of(context).size.width *
imageWidth);

Uint8List? result = await contentRecorderCtrl.captureFromWidget(
layer.sticker,
format: OutputFormat.png,
imageInfos: imageInfos,
targetSize: targetSize,
);
if (result == null) return;
Uint8List? result;
if (_configs.serializeSticker) {
double imageWidth =
editorConfigs.stickerEditor.initWidth * layer.scale;
Size targetSize = Size(
imageWidth,
MediaQuery.of(context).size.height /
MediaQuery.of(context).size.width *
imageWidth);

result = await contentRecorderCtrl.captureFromWidget(
layer.sticker,
format: OutputFormat.png,
imageInfos: imageInfos,
targetSize: targetSize,
);
if (result == null) return;
} else {
result = Uint8List.fromList([]);
}

stickers.add(result);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/models/import_export/export_state_history_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ExportEditorConfigs {
this.exportTuneAdjustments = true,
this.exportEmoji = true,
this.exportSticker = true,
this.serializeSticker = true,
});

/// The span of the export history to include in the export.
Expand Down Expand Up @@ -59,4 +60,17 @@ class ExportEditorConfigs {
///
/// Warning: Exporting stickers may result in increased file size.
final bool exportSticker;

/// Controls whether stickers should be serialized.
///
/// When enabled, each sticker widget is converted to a `Uint8List` and
/// included in the export history.
/// **Note:** Enabling this flag with a large number of stickers can
/// significantly increase the size of the JSON file.
///
/// Defaults to `true`.
///
/// **Warning:** Disabling sticker serialization may result in the loss of
/// stickers during export.
final bool serializeSticker;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pro_image_editor
description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features."
version: 7.1.1
version: 7.2.0
homepage: https://github.com/hm21/pro_image_editor/
repository: https://github.com/hm21/pro_image_editor/
issue_tracker: https://github.com/hm21/pro_image_editor/issues/
Expand Down

0 comments on commit 60d9c7f

Please sign in to comment.