Make thumbnail width height and quality configurable
This commit is contained in:
parent
f65ef4cdcf
commit
0e3fabcef3
|
@ -478,7 +478,9 @@ class Room {
|
||||||
Event inReplyTo,
|
Event inReplyTo,
|
||||||
Map<String, dynamic> info,
|
Map<String, dynamic> info,
|
||||||
bool waitUntilSent = false,
|
bool waitUntilSent = false,
|
||||||
int thumbnailSize = Client.defaultThumbnailSize,
|
int thumbnailMaxWidth = 800,
|
||||||
|
int thumbnailMaxHeight = 600,
|
||||||
|
int thumbnailQuality = 50,
|
||||||
}) async {
|
}) async {
|
||||||
Image fileImage;
|
Image fileImage;
|
||||||
Image thumbnailImage;
|
Image thumbnailImage;
|
||||||
|
@ -507,7 +509,11 @@ class Room {
|
||||||
thumbnailPathParts.last = 'thumbnail_' + thumbnailPathParts.last + '.jpg';
|
thumbnailPathParts.last = 'thumbnail_' + thumbnailPathParts.last + '.jpg';
|
||||||
final thumbnailPath = thumbnailPathParts.join('/');
|
final thumbnailPath = thumbnailPathParts.join('/');
|
||||||
thumbnail = MatrixFile(bytes: file.bytes, path: thumbnailPath);
|
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());
|
fileImage = decodeImage(file.bytes.toList());
|
||||||
thumbnailImage = decodeImage(thumbnail.bytes.toList());
|
thumbnailImage = decodeImage(thumbnail.bytes.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,11 @@ class MatrixFile {
|
||||||
/// given width and height. Otherwise returns false.
|
/// given width and height. Otherwise returns false.
|
||||||
/// At least width or height must be set!
|
/// At least width or height must be set!
|
||||||
/// The bytes will be encoded as jpg.
|
/// 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) {
|
if (width == null && height == null) {
|
||||||
throw ('At least width or height must be set!');
|
throw ('At least width or height must be set!');
|
||||||
}
|
}
|
||||||
|
@ -24,7 +28,7 @@ class MatrixFile {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final resizedImage = copyResize(image, width: width, height: height);
|
final resizedImage = copyResize(image, width: width, height: height);
|
||||||
bytes = encodeJpg(resizedImage, quality: 10);
|
bytes = encodeJpg(resizedImage, quality: quality);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue