mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 14:32:37 +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 &&
|
||||
!origImage &&
|
||||
file.bytes.length > minSizeToCompress) {
|
||||
file = await file.resizeImage(quality: 40, max: 1200);
|
||||
file = await file.resizeImage();
|
||||
}
|
||||
await widget.room.sendFileEventWithThumbnail(file);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import 'package:image/image.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
extension ResizeImage on MatrixFile {
|
||||
static const int max = 800;
|
||||
static const int quality = 20;
|
||||
static const int max = 1200;
|
||||
static const int quality = 40;
|
||||
|
||||
Future<MatrixImageFile> resizeImage({
|
||||
bool calcBlurhash = true,
|
||||
@ -23,7 +23,8 @@ extension ResizeImage on MatrixFile {
|
||||
: await compute<_ResizeBytesConfig, Uint8List>(
|
||||
resizeBytes,
|
||||
_ResizeBytesConfig(
|
||||
this.bytes,
|
||||
bytes: this.bytes,
|
||||
mimeType: mimeType,
|
||||
max: max,
|
||||
quality: quality,
|
||||
));
|
||||
@ -55,17 +56,24 @@ Future<Uint8List> resizeBytes(_ResizeBytesConfig config) async {
|
||||
: 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 {
|
||||
final Uint8List bytes;
|
||||
final int max;
|
||||
final int quality;
|
||||
final String mimeType;
|
||||
|
||||
const _ResizeBytesConfig(
|
||||
this.bytes, {
|
||||
const _ResizeBytesConfig({
|
||||
required this.bytes,
|
||||
this.max = ResizeImage.max,
|
||||
this.quality = ResizeImage.quality,
|
||||
required this.mimeType,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user