Merge pull request 'fix null resilution bug' (#449) from jmplace/ScoDoc-Lille:fix_null_density_bug into master

Reviewed-on: https://scodoc.org/git/ScoDoc/ScoDoc/pulls/449
This commit is contained in:
Emmanuel Viennet 2022-07-14 12:19:01 +02:00
commit 40e9fe6c84

View File

@ -136,7 +136,9 @@ def _list_dept_logos(dept_id=None, prefix=scu.LOGO_FILE_PREFIX):
if os.access(path_dir.joinpath(entry).absolute(), os.R_OK): if os.access(path_dir.joinpath(entry).absolute(), os.R_OK):
result = filename_parser.match(entry.name) result = filename_parser.match(entry.name)
if result: if result:
logoname = result.group(1)[:-1] # retreive logoname from filename (less final dot) logoname = result.group(1)[
:-1
] # retreive logoname from filename (less final dot)
logos[logoname] = Logo(logoname=logoname, dept_id=dept_id).select() logos[logoname] = Logo(logoname=logoname, dept_id=dept_id).select()
return logos if len(logos.keys()) > 0 else None return logos if len(logos.keys()) > 0 else None
@ -235,7 +237,7 @@ class Logo:
unit = img.info.get("jfif_unit", 0) # 0 = no unit ; 1 = inch ; 2 = mm unit = img.info.get("jfif_unit", 0) # 0 = no unit ; 1 = inch ; 2 = mm
if self.density is not None: if self.density is not None:
x_density, y_density = self.density x_density, y_density = self.density
if unit != 0: if unit != 0 and x_density != 0 and y_density != 0:
unit2mm = [0, 1 / 0.254, 0.1][unit] unit2mm = [0, 1 / 0.254, 0.1][unit]
x_mm = round(x_size * unit2mm / x_density, 2) x_mm = round(x_size * unit2mm / x_density, 2)
y_mm = round(y_size * unit2mm / y_density, 2) y_mm = round(y_size * unit2mm / y_density, 2)
@ -244,7 +246,6 @@ class Logo:
self.mm = None self.mm = None
else: else:
self.mm = None self.mm = None
self.size = (x_size, y_size) self.size = (x_size, y_size)
self.aspect_ratio = round(float(x_size) / y_size, 2) self.aspect_ratio = round(float(x_size) / y_size, 2)