Skip to content

Commit

Permalink
udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraalex committed Nov 1, 2024
1 parent 5b8186b commit 45c2132
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions streaming/base/format/mds/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,14 @@ class JPEG(Encoding):
"""Store PIL image as JPEG. Optionally specify quality."""

def __init__(self, quality: int = 75):
if not isinstance(quality, int):
raise ValueError('JPEG quality must be an integer')
if not (0 <= quality <= 100):
raise ValueError('JPEG quality must be between 0 and 100')
self.quality = quality

@classmethod
def from_str(cls, text: str) -> Self:
def from_str(cls, config: str) -> Self:
"""Parse this encoding from string.
Args:
Expand All @@ -481,17 +483,10 @@ def from_str(cls, text: str) -> Self:
Returns:
Self: The initialized Encoding.
"""
args = text.split(':') if text else []
if len(args) not in {0, 1}:
raise ValueError('JPEG encoding string must have 0 or 1 arguments')
if len(args) == 1:
try:
quality = int(args[0])
except ValueError:
raise ValueError('JPEG quality must be an integer between 0 and 100')
if config == '':
return cls()
else:
quality = 75
return cls(quality)
return cls(int(config))

def encode(self, obj: Image.Image) -> bytes:
self._validate(obj, Image.Image)
Expand Down

0 comments on commit 45c2132

Please sign in to comment.