Merge branch 'krille/non-blurry-thumbnails' into 'master'
Fix blurry thumbnails See merge request famedly/famedlysdk!276
This commit is contained in:
commit
cdadbe88a8
|
@ -489,7 +489,6 @@ class Client {
|
||||||
|
|
||||||
/// Uploads a new user avatar for this user.
|
/// Uploads a new user avatar for this user.
|
||||||
Future<void> setAvatar(MatrixFile file) async {
|
Future<void> setAvatar(MatrixFile file) async {
|
||||||
await file.resize(width: Client.defaultThumbnailSize);
|
|
||||||
final uploadResp = await upload(file);
|
final uploadResp = await upload(file);
|
||||||
await jsonRequest(
|
await jsonRequest(
|
||||||
type: HTTPType.PUT,
|
type: HTTPType.PUT,
|
||||||
|
|
|
@ -478,13 +478,10 @@ class Room {
|
||||||
Event inReplyTo,
|
Event inReplyTo,
|
||||||
Map<String, dynamic> info,
|
Map<String, dynamic> info,
|
||||||
bool waitUntilSent = false,
|
bool waitUntilSent = false,
|
||||||
int thumbnailMaxWidth = 800,
|
MatrixFile thumbnail,
|
||||||
int thumbnailMaxHeight = 600,
|
|
||||||
int thumbnailQuality = 50,
|
|
||||||
}) async {
|
}) async {
|
||||||
Image fileImage;
|
Image fileImage;
|
||||||
Image thumbnailImage;
|
Image thumbnailImage;
|
||||||
MatrixFile thumbnail;
|
|
||||||
EncryptedFile encryptedThumbnail;
|
EncryptedFile encryptedThumbnail;
|
||||||
String thumbnailUploadResp;
|
String thumbnailUploadResp;
|
||||||
|
|
||||||
|
@ -505,18 +502,11 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgType == 'm.image') {
|
if (msgType == 'm.image') {
|
||||||
var thumbnailPathParts = file.path.split('/');
|
|
||||||
thumbnailPathParts.last = 'thumbnail_' + thumbnailPathParts.last + '.jpg';
|
|
||||||
final thumbnailPath = thumbnailPathParts.join('/');
|
|
||||||
thumbnail = MatrixFile(bytes: file.bytes, path: thumbnailPath);
|
|
||||||
await thumbnail.resize(
|
|
||||||
width: thumbnailMaxWidth,
|
|
||||||
height: thumbnailMaxHeight,
|
|
||||||
quality: thumbnailQuality,
|
|
||||||
);
|
|
||||||
fileImage = decodeImage(file.bytes.toList());
|
fileImage = decodeImage(file.bytes.toList());
|
||||||
|
if (thumbnail != null) {
|
||||||
thumbnailImage = decodeImage(thumbnail.bytes.toList());
|
thumbnailImage = decodeImage(thumbnail.bytes.toList());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final sendEncrypted = encrypted && client.fileEncryptionEnabled;
|
final sendEncrypted = encrypted && client.fileEncryptionEnabled;
|
||||||
EncryptedFile encryptedFile;
|
EncryptedFile encryptedFile;
|
||||||
|
@ -1257,7 +1247,6 @@ class Room {
|
||||||
/// Uploads a new user avatar for this room. Returns the event ID of the new
|
/// Uploads a new user avatar for this room. Returns the event ID of the new
|
||||||
/// m.room.avatar event.
|
/// m.room.avatar event.
|
||||||
Future<String> setAvatar(MatrixFile file) async {
|
Future<String> setAvatar(MatrixFile file) async {
|
||||||
await file.resize(width: Client.defaultThumbnailSize);
|
|
||||||
final uploadResp = await client.upload(file);
|
final uploadResp = await client.upload(file);
|
||||||
final setAvatarResp = await client.jsonRequest(
|
final setAvatarResp = await client.jsonRequest(
|
||||||
type: HTTPType.PUT,
|
type: HTTPType.PUT,
|
||||||
|
|
|
@ -1,43 +1,12 @@
|
||||||
/// Workaround until [File] in dart:io and dart:html is unified
|
/// Workaround until [File] in dart:io and dart:html is unified
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:image/image.dart';
|
|
||||||
import 'package:matrix_file_e2ee/matrix_file_e2ee.dart';
|
import 'package:matrix_file_e2ee/matrix_file_e2ee.dart';
|
||||||
|
|
||||||
class MatrixFile {
|
class MatrixFile {
|
||||||
Uint8List bytes;
|
Uint8List bytes;
|
||||||
String path;
|
String path;
|
||||||
|
|
||||||
/// If this file is an Image, this will resize it to the
|
|
||||||
/// 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,
|
|
||||||
int quality = 50,
|
|
||||||
}) async {
|
|
||||||
if (width == null && height == null) {
|
|
||||||
throw ('At least width or height must be set!');
|
|
||||||
}
|
|
||||||
Image image;
|
|
||||||
try {
|
|
||||||
image = decodeImage(bytes);
|
|
||||||
} catch (_) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var resizedImage = image;
|
|
||||||
if (image.width > width) {
|
|
||||||
resizedImage = copyResize(image, width: width);
|
|
||||||
}
|
|
||||||
if (image.height > height) {
|
|
||||||
resizedImage = copyResize(image, height: height);
|
|
||||||
}
|
|
||||||
bytes = encodeJpg(resizedImage, quality: quality);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encrypts this file, changes the [bytes] and returns the
|
/// Encrypts this file, changes the [bytes] and returns the
|
||||||
/// encryption information as an [EncryptedFile].
|
/// encryption information as an [EncryptedFile].
|
||||||
Future<EncryptedFile> encrypt() async {
|
Future<EncryptedFile> encrypt() async {
|
||||||
|
|
Loading…
Reference in a new issue