Merge branch 'krille/thumbnail-size-fix' into 'master'

Make thumbnail width height and quality configurable

See merge request famedly/famedlysdk!272
This commit is contained in:
Christian Pauly 2020-05-04 07:03:23 +00:00
commit 197838b028
2 changed files with 14 additions and 4 deletions

View file

@ -478,7 +478,9 @@ class Room {
Event inReplyTo,
Map<String, dynamic> info,
bool waitUntilSent = false,
int thumbnailSize = Client.defaultThumbnailSize,
int thumbnailMaxWidth = 800,
int thumbnailMaxHeight = 600,
int thumbnailQuality = 50,
}) async {
Image fileImage;
Image thumbnailImage;
@ -507,7 +509,11 @@ class Room {
thumbnailPathParts.last = 'thumbnail_' + thumbnailPathParts.last + '.jpg';
final thumbnailPath = thumbnailPathParts.join('/');
thumbnail = MatrixFile(bytes: file.bytes, path: thumbnailPath);
await thumbnail.resize(width: thumbnailSize);
await thumbnail.resize(
width: thumbnailMaxWidth,
height: thumbnailMaxHeight,
quality: thumbnailQuality,
);
fileImage = decodeImage(file.bytes.toList());
thumbnailImage = decodeImage(thumbnail.bytes.toList());
}

View file

@ -13,7 +13,11 @@ class MatrixFile {
/// given width and height. Otherwise returns false.
/// At least width or height must be set!
/// The bytes will be encoded as jpg.
Future<bool> resize({int width, int height}) async {
Future<bool> resize({
int width,
int height,
int quality = 50,
}) async {
if (width == null && height == null) {
throw ('At least width or height must be set!');
}
@ -24,7 +28,7 @@ class MatrixFile {
return false;
}
final resizedImage = copyResize(image, width: width, height: height);
bytes = encodeJpg(resizedImage, quality: 10);
bytes = encodeJpg(resizedImage, quality: quality);
return true;
}