From efa48239e41a4cc25dd8b1c82b01ed014235ae51 Mon Sep 17 00:00:00 2001 From: vltclz Date: Fri, 23 Feb 2024 14:52:56 +0100 Subject: [PATCH] bugfix: story height resize --- instagrapi/mixins/photo.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/instagrapi/mixins/photo.py b/instagrapi/mixins/photo.py index 73f297d6..5ea3e91c 100644 --- a/instagrapi/mixins/photo.py +++ b/instagrapi/mixins/photo.py @@ -124,7 +124,11 @@ class UploadPhotoMixin: """ def photo_rupload( - self, path: Path, upload_id: str = "", to_album: bool = False + self, + path: Path, + upload_id: str = "", + to_album: bool = False, + for_story: bool = False, ) -> tuple: """ Upload photo to Instagram @@ -136,6 +140,8 @@ def photo_rupload( upload_id: str, optional Unique upload_id (String). When None, then generate automatically. Example from video.video_configure to_album: bool, optional + for_story: bool, optional + Useful for resize util only Returns ------- @@ -174,7 +180,15 @@ def photo_rupload( } if to_album: rupload_params["is_sidecar"] = "1" - photo_data, photo_size = prepare_image(str(path), max_side=1080) + if for_story: + photo_data, photo_size = prepare_image( + str(path), + max_side=1080, + aspect_ratios=(9 / 16, 90 / 47), + max_size=(1080, 1920), + ) + else: + photo_data, photo_size = prepare_image(str(path), max_side=1080) photo_len = str(len(photo_data)) headers = { "Accept-Encoding": "gzip", @@ -381,7 +395,7 @@ def photo_upload_to_story( An object of Media class """ path = Path(path) - upload_id, width, height = self.photo_rupload(path, upload_id) + upload_id, width, height = self.photo_rupload(path, upload_id, for_story=True) for attempt in range(10): self.logger.debug(f"Attempt #{attempt} to configure Photo: {path}") time.sleep(3)