Change summary
src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 12
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 3
2 files changed, 14 insertions(+), 1 deletion(-)
Detailed changes
@@ -687,6 +687,18 @@ public class FileBackend {
updateFileParams(message);
}
+ public boolean unusualBounds(Uri image) {
+ try {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(image), null, options);
+ float ratio = (float) options.outHeight / options.outWidth;
+ return ratio > (21.0f / 9.0f) || ratio < (9.0f / 21.0f);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
private int getRotation(File file) {
return getRotation(Uri.parse("file://" + file.getAbsolutePath()));
}
@@ -504,7 +504,8 @@ public class XmppConnectionService extends Service {
if ("never".equals(compressPictures)
|| ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri))
- || (mimeType != null && mimeType.endsWith("/gif"))) {
+ || (mimeType != null && mimeType.endsWith("/gif"))
+ || getFileBackend().unusualBounds(uri)) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": not compressing picture. sending as file");
attachFileToConversation(conversation, uri, mimeType, callback);
return;