aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/func/images.py
diff options
context:
space:
mode:
authorrr-2017-02-04 01:08:12 +0100
committerrr-2017-02-05 16:34:45 +0100
commitad842ee8a54c57463b8e28b52970f173ea1d64ea (patch)
tree1238e8270878801a2ddb10bc4db469115c026cab /server/szurubooru/func/images.py
parentabf1fc2b2d135299fe7e8a700d4e7a18966d7bfe (diff)
server: refactor + add type hinting
- Added type hinting (for now, 3.5-compatible) - Split `db` namespace into `db` module and `model` namespace - Changed elastic search to be created lazily for each operation - Changed to class based approach in entity serialization to allow stronger typing - Removed `required` argument from `context.get_*` family of functions; now it's implied if `default` argument is omitted - Changed `unalias_dict` implementation to use less magic inputs
Diffstat (limited to 'server/szurubooru/func/images.py')
-rw-r--r--server/szurubooru/func/images.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py
index fdab793..103a6ff 100644
--- a/server/szurubooru/func/images.py
+++ b/server/szurubooru/func/images.py
@@ -1,3 +1,4 @@
+from typing import List
import logging
import json
import shlex
@@ -15,23 +16,23 @@ _SCALE_FIT_FMT = \
class Image:
- def __init__(self, content):
+ def __init__(self, content: bytes) -> None:
self.content = content
self._reload_info()
@property
- def width(self):
+ def width(self) -> int:
return self.info['streams'][0]['width']
@property
- def height(self):
+ def height(self) -> int:
return self.info['streams'][0]['height']
@property
- def frames(self):
+ def frames(self) -> int:
return self.info['streams'][0]['nb_read_frames']
- def resize_fill(self, width, height):
+ def resize_fill(self, width: int, height: int) -> None:
cli = [
'-i', '{path}',
'-f', 'image2',
@@ -53,7 +54,7 @@ class Image:
assert self.content
self._reload_info()
- def to_png(self):
+ def to_png(self) -> bytes:
return self._execute([
'-i', '{path}',
'-f', 'image2',
@@ -63,7 +64,7 @@ class Image:
'-',
])
- def to_jpeg(self):
+ def to_jpeg(self) -> bytes:
return self._execute([
'-f', 'lavfi',
'-i', 'color=white:s=%dx%d' % (self.width, self.height),
@@ -76,7 +77,7 @@ class Image:
'-',
])
- def _execute(self, cli, program='ffmpeg'):
+ def _execute(self, cli: List[str], program: str='ffmpeg') -> bytes:
extension = mime.get_extension(mime.get_mime_type(self.content))
assert extension
with util.create_temp_file(suffix='.' + extension) as handle:
@@ -99,7 +100,7 @@ class Image:
'Error while processing image.\n' + err.decode('utf-8'))
return out
- def _reload_info(self):
+ def _reload_info(self) -> None:
self.info = json.loads(self._execute([
'-i', '{path}',
'-of', 'json',

© 2015 - 2026 Jakob L. Kreuze