diff --git a/src/sticker_convert/job_option.py b/src/sticker_convert/job_option.py index 347a93a..ec5d91c 100755 --- a/src/sticker_convert/job_option.py +++ b/src/sticker_convert/job_option.py @@ -80,7 +80,6 @@ class CompOption(BaseOption): no_compress: Optional[bool] = None processes: int = ceil(cpu_count() / 2) animated: Optional[bool] = None - square: Optional[bool] = None def to_dict(self) -> Dict[Any, Any]: return { @@ -115,7 +114,6 @@ def to_dict(self) -> Dict[Any, Any]: "no_compress": self.no_compress, "processes": self.processes, "animated": self.animated, - "square": self.square, } def get_size_max(self) -> Tuple[Optional[int], Optional[int]]: diff --git a/src/sticker_convert/uploaders/compress_wastickers.py b/src/sticker_convert/uploaders/compress_wastickers.py index 4cdfab5..da515fe 100755 --- a/src/sticker_convert/uploaders/compress_wastickers.py +++ b/src/sticker_convert/uploaders/compress_wastickers.py @@ -23,7 +23,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.base_spec.size_max_vid = 500000 self.base_spec.duration_min = 8 self.base_spec.duration_max = 10000 - self.base_spec.square = True self.base_spec.set_res(512) self.base_spec.set_format((".webp",)) diff --git a/src/sticker_convert/uploaders/upload_signal.py b/src/sticker_convert/uploaders/upload_signal.py index 49cab20..056e9a1 100755 --- a/src/sticker_convert/uploaders/upload_signal.py +++ b/src/sticker_convert/uploaders/upload_signal.py @@ -25,7 +25,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.base_spec.set_size_max(300000) self.base_spec.set_res_max(512) self.base_spec.duration_max = 3000 - self.base_spec.square = True self.png_spec = copy.deepcopy(self.base_spec) self.png_spec.set_format((".apng",)) diff --git a/src/sticker_convert/uploaders/upload_telegram.py b/src/sticker_convert/uploaders/upload_telegram.py index 267c335..8ae32c0 100755 --- a/src/sticker_convert/uploaders/upload_telegram.py +++ b/src/sticker_convert/uploaders/upload_telegram.py @@ -24,7 +24,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.base_spec.size_max_img = 512000 self.base_spec.size_max_vid = 256000 - self.base_spec.square = True self.base_spec.duration_max = 3000 self.base_spec.set_res(512) @@ -48,7 +47,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.opt_comp_merged.merge(self.base_spec) base_cover_spec = CompOption( - size_max_img=128000, size_max_vid=32000, square=True, duration_max=3000 + size_max_img=128000, size_max_vid=32000, duration_max=3000 ) base_cover_spec.set_res(100) diff --git a/src/sticker_convert/uploaders/upload_viber.py b/src/sticker_convert/uploaders/upload_viber.py index 61e03ad..1a80423 100755 --- a/src/sticker_convert/uploaders/upload_viber.py +++ b/src/sticker_convert/uploaders/upload_viber.py @@ -23,7 +23,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.base_spec.set_size_max(0) - self.base_spec.square = True self.png_spec = copy.deepcopy(self.base_spec) self.png_spec.set_res_max(490) diff --git a/src/sticker_convert/uploaders/xcode_imessage.py b/src/sticker_convert/uploaders/xcode_imessage.py index 732c44e..c80d939 100755 --- a/src/sticker_convert/uploaders/xcode_imessage.py +++ b/src/sticker_convert/uploaders/xcode_imessage.py @@ -25,7 +25,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.base_spec.set_size_max(500000) self.base_spec.set_res(300) self.base_spec.set_format(("png", ".apng", ".gif", ".jpeg", "jpg")) - self.base_spec.square = True self.small_spec = copy.deepcopy(self.base_spec) diff --git a/src/sticker_convert/utils/media/format_verify.py b/src/sticker_convert/utils/media/format_verify.py index bbb63e4..2554911 100755 --- a/src/sticker_convert/utils/media/format_verify.py +++ b/src/sticker_convert/utils/media/format_verify.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import os +from fractions import Fraction from pathlib import Path from typing import Optional, Tuple, Union @@ -16,9 +17,7 @@ def check_file(file: Union[Path, bytes], spec: CompOption) -> bool: file_info = CodecInfo(file) return ( - FormatVerify.check_file_res( - file, res=spec.get_res(), square=spec.square, file_info=file_info - ) + FormatVerify.check_file_res(file, res=spec.get_res(), file_info=file_info) and FormatVerify.check_file_fps( file, fps=spec.get_fps(), file_info=file_info ) @@ -48,7 +47,6 @@ def check_file_res( res: Tuple[ Tuple[Optional[int], Optional[int]], Tuple[Optional[int], Optional[int]] ], - square: Optional[bool] = None, file_info: Optional[CodecInfo] = None, ) -> bool: if file_info: @@ -65,8 +63,27 @@ def check_file_res( return False if res[1][1] and file_height > res[1][1]: return False - if square and file_height != file_width: - return False + + min_ratio = None + if res[0][0] and res[1][0]: + min_ratio = Fraction(res[0][0], res[1][0]) + + max_ratio = None + if res[0][1] and res[1][1]: + max_ratio = Fraction(res[0][1], res[1][1]) + + file_ratio = Fraction(file_width, file_height) + + if min_ratio is not None and max_ratio is not None: + if min_ratio == max_ratio: + return True if file_ratio == min_ratio else False + else: + return True + + if min_ratio is not None: + return True if file_ratio == min_ratio else False + if max_ratio is not None: + return True if file_ratio == max_ratio else False return True