Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for GIFs #53

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion custom_components/llmvision/media_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ async def resize_image(self, target_width, image_path=None, image_data=None, img
# Open the image file
img = await self.hass.loop.run_in_executor(None, Image.open, image_path)
with img:
# Check if the image is a GIF and convert if necessary
if img.format == 'GIF':
# Convert GIF to RGB
img = img.convert('RGB')
# calculate new height based on aspect ratio
width, height = img.size
aspect_ratio = width / height
Expand All @@ -45,7 +49,7 @@ async def resize_image(self, target_width, image_path=None, image_data=None, img
if width > target_width or height > target_height:
img = img.resize((target_width, target_height))

# Convert the image to base64
# Encode the image to base64
base64_image = await self._encode_image(img)

elif image_data:
Expand Down
Loading