aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-09-27 20:08:49 +0200
committerChristian Schneppe <christian@pix-art.de>2018-09-27 20:08:49 +0200
commit5b9784a7898451ad867ba1e25d151a6b6d97da8d (patch)
tree51b9265dd332ecdf8f61e1b7864b7cd1450b1f17 /src/main/java
parentf67821752d81253478ac248e62482d6d89427e41 (diff)
do not compress/resize images with strange aspect ratios
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java12
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java3
2 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 822fa6318..8397a7bb8 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -491,6 +491,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()));
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 396a68446..132ede7b6 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -522,7 +522,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;