From 8b4f645a65267fb10c4b6d519cb0d0f62dba94ca Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Sun, 5 May 2019 20:35:10 +0200 Subject: [PATCH] prosopopee: add ratio property for images To prepare for an alignment fix that requires to know the ratio of the image, let's add a ratio property. This property is calling `gm identify` which is already a dependency of prosopopee. The output of this particular `gm identify` returns the width and height separated by a comma. Signed-off-by: Quentin Schulz --- prosopopee/prosopopee.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 6499e61..dfc474e 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -16,6 +16,7 @@ Options: import os import shutil import socketserver +import subprocess import http.server import ruamel.yaml as yaml @@ -266,6 +267,13 @@ class Image(object): return thumbnail_name + @property + def ratio(self): + command = "gm identify -format %w,%h " + self.base_dir.joinpath(self.name) + out = subprocess.check_output(command.split()) + width,height = out.split(',') + return float(width) / int(height) + def __repr__(self): return self.name