mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 14:30:40 +01:00
Merge branch 'krille/better-thumbnails' into 'main'
fix: Better thumbnails Closes #696 and #697 See merge request famedly/fluffychat!618
This commit is contained in:
commit
cf70348200
@ -36,7 +36,7 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
|||||||
if (file is MatrixImageFile &&
|
if (file is MatrixImageFile &&
|
||||||
!origImage &&
|
!origImage &&
|
||||||
file.bytes.length > minSizeToCompress) {
|
file.bytes.length > minSizeToCompress) {
|
||||||
file = await file.resizeImage(quality: 40, max: 1200);
|
file = await file.resizeImage();
|
||||||
}
|
}
|
||||||
await widget.room.sendFileEventWithThumbnail(file);
|
await widget.room.sendFileEventWithThumbnail(file);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import 'package:image/image.dart';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
extension ResizeImage on MatrixFile {
|
extension ResizeImage on MatrixFile {
|
||||||
static const int max = 800;
|
static const int max = 1200;
|
||||||
static const int quality = 20;
|
static const int quality = 40;
|
||||||
|
|
||||||
Future<MatrixImageFile> resizeImage({
|
Future<MatrixImageFile> resizeImage({
|
||||||
bool calcBlurhash = true,
|
bool calcBlurhash = true,
|
||||||
@ -23,7 +23,8 @@ extension ResizeImage on MatrixFile {
|
|||||||
: await compute<_ResizeBytesConfig, Uint8List>(
|
: await compute<_ResizeBytesConfig, Uint8List>(
|
||||||
resizeBytes,
|
resizeBytes,
|
||||||
_ResizeBytesConfig(
|
_ResizeBytesConfig(
|
||||||
this.bytes,
|
bytes: this.bytes,
|
||||||
|
mimeType: mimeType,
|
||||||
max: max,
|
max: max,
|
||||||
quality: quality,
|
quality: quality,
|
||||||
));
|
));
|
||||||
@ -55,17 +56,24 @@ Future<Uint8List> resizeBytes(_ResizeBytesConfig config) async {
|
|||||||
: copyResize(image, height: config.max);
|
: copyResize(image, height: config.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Uint8List.fromList(encodeJpg(image, quality: config.quality));
|
const pngMimeType = 'image/png';
|
||||||
|
final encoded = config.mimeType.toLowerCase() == pngMimeType
|
||||||
|
? encodePng(image)
|
||||||
|
: encodeJpg(image, quality: config.quality);
|
||||||
|
|
||||||
|
return Uint8List.fromList(encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ResizeBytesConfig {
|
class _ResizeBytesConfig {
|
||||||
final Uint8List bytes;
|
final Uint8List bytes;
|
||||||
final int max;
|
final int max;
|
||||||
final int quality;
|
final int quality;
|
||||||
|
final String mimeType;
|
||||||
|
|
||||||
const _ResizeBytesConfig(
|
const _ResizeBytesConfig({
|
||||||
this.bytes, {
|
required this.bytes,
|
||||||
this.max = ResizeImage.max,
|
this.max = ResizeImage.max,
|
||||||
this.quality = ResizeImage.quality,
|
this.quality = ResizeImage.quality,
|
||||||
|
required this.mimeType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user