summaryrefslogtreecommitdiff
path: root/synapse/rest/media/v1/thumbnail_resource.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@matrix.org>2016-02-10 16:22:15 +0000
committerErik Johnston <erikj@matrix.org>2016-02-10 16:22:15 +0000
commit8e514df559bc1fadadf6ead5178537d0352ae221 (patch)
treee9f18d4f3044cab76ab5ae119505ea651194db5e /synapse/rest/media/v1/thumbnail_resource.py
parent2c402214a9fe51677adf05424cca7918b91c7949 (diff)
Imported Upstream version 0.13.0
Diffstat (limited to 'synapse/rest/media/v1/thumbnail_resource.py')
-rw-r--r--synapse/rest/media/v1/thumbnail_resource.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/synapse/rest/media/v1/thumbnail_resource.py b/synapse/rest/media/v1/thumbnail_resource.py
index e506dad9..ab524997 100644
--- a/synapse/rest/media/v1/thumbnail_resource.py
+++ b/synapse/rest/media/v1/thumbnail_resource.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright 2014, 2015 OpenMarket Ltd
+# Copyright 2014 - 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -248,22 +248,31 @@ class ThumbnailResource(BaseMediaResource):
if desired_method.lower() == "crop":
info_list = []
+ info_list2 = []
for info in thumbnail_infos:
t_w = info["thumbnail_width"]
t_h = info["thumbnail_height"]
t_method = info["thumbnail_method"]
- if t_method == "scale" or t_method == "crop":
+ if t_method == "crop":
aspect_quality = abs(d_w * t_h - d_h * t_w)
min_quality = 0 if d_w <= t_w and d_h <= t_h else 1
size_quality = abs((d_w - t_w) * (d_h - t_h))
type_quality = desired_type != info["thumbnail_type"]
length_quality = info["thumbnail_length"]
- info_list.append((
- aspect_quality, min_quality, size_quality, type_quality,
- length_quality, info
- ))
+ if t_w >= d_w or t_h >= d_h:
+ info_list.append((
+ aspect_quality, min_quality, size_quality, type_quality,
+ length_quality, info
+ ))
+ else:
+ info_list2.append((
+ aspect_quality, min_quality, size_quality, type_quality,
+ length_quality, info
+ ))
if info_list:
return min(info_list)[-1]
+ else:
+ return min(info_list2)[-1]
else:
info_list = []
info_list2 = []