Improve the resolution of the compressed thumbnail
This commit is contained in:
parent
51b08a242f
commit
da2cb1b2cf
2 changed files with 20 additions and 20 deletions
|
@ -149,19 +149,13 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
|
|||
|
||||
void _getThumbnailFromServer() {
|
||||
getThumbnailFromServer(widget.file).then((file) async {
|
||||
var imageProvider;
|
||||
if (file.lengthSync() > THUMBNAIL_DATA_LIMIT) {
|
||||
final compressed = await FlutterImageCompress.compressWithFile(
|
||||
file.path,
|
||||
quality: 25,
|
||||
minHeight: THUMBNAIL_SMALL_SIZE,
|
||||
minWidth: THUMBNAIL_SMALL_SIZE,
|
||||
);
|
||||
imageProvider = Image.memory(compressed).image;
|
||||
} else {
|
||||
imageProvider = Image.file(file).image;
|
||||
_logger.warning(widget.file.title +
|
||||
" has a thumbnail of size " +
|
||||
file.lengthSync().toString());
|
||||
}
|
||||
if (mounted) {
|
||||
final imageProvider = Image.file(file).image;
|
||||
precacheImage(imageProvider, context).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
|
|
@ -241,9 +241,6 @@ Future<io.File> _downloadAndDecrypt(File file, BaseCacheManager cacheManager,
|
|||
}
|
||||
|
||||
Future<io.File> _downloadAndDecryptThumbnail(File file) async {
|
||||
_logger.info("Downloading thumbnail for " + file.uploadedFileID.toString());
|
||||
_logger.info("Downloads in progress " +
|
||||
thumbnailDownloadsInProgress.length.toString());
|
||||
final temporaryPath = Configuration.instance.getTempDirectory() +
|
||||
file.generatedID.toString() +
|
||||
"_thumbnail.decrypted";
|
||||
|
@ -258,13 +255,13 @@ Future<io.File> _downloadAndDecryptThumbnail(File file) async {
|
|||
thumbnailDecryptionKey,
|
||||
Sodium.base642bin(file.thumbnailDecryptionHeader),
|
||||
);
|
||||
if (data.length > THUMBNAIL_DATA_LIMIT) {
|
||||
data = await FlutterImageCompress.compressWithList(
|
||||
data,
|
||||
quality: 50,
|
||||
minHeight: THUMBNAIL_SMALL_SIZE,
|
||||
minWidth: THUMBNAIL_SMALL_SIZE,
|
||||
);
|
||||
final thumbnailSize = data.length;
|
||||
if (thumbnailSize > THUMBNAIL_DATA_LIMIT) {
|
||||
data = await compressThumbnail(data);
|
||||
_logger.info("Compressed thumbnail from " +
|
||||
thumbnailSize.toString() +
|
||||
" to " +
|
||||
data.length.toString());
|
||||
}
|
||||
encryptedFile.deleteSync();
|
||||
final cachedThumbnail = ThumbnailCacheManager().putFile(
|
||||
|
@ -288,3 +285,12 @@ Uint8List decryptFileKey(File file) {
|
|||
CollectionsService.instance.getCollectionKey(file.collectionID);
|
||||
return CryptoUtil.decryptSync(encryptedKey, collectionKey, nonce);
|
||||
}
|
||||
|
||||
Future<Uint8List> compressThumbnail(Uint8List thumbnail) {
|
||||
return FlutterImageCompress.compressWithList(
|
||||
thumbnail,
|
||||
minHeight: 1080,
|
||||
minWidth: 1080,
|
||||
quality: 25,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue