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 <foss@0leil.net>
This commit is contained in:
Quentin Schulz 2019-05-05 20:35:10 +02:00
parent c0efbba51c
commit 8b4f645a65

View File

@ -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