2525 ThumbnailJob ,
2626 ThumbnailSourceJob ,
2727)
28+ from .pillow_resize_and_crop import transform_image
2829
2930logger = logging .getLogger ("bma_client" )
3031
@@ -248,7 +249,7 @@ def write_and_upload_result(self, job: Job, result: "JobResult", filename: str)
248249 metadata : dict [str , int | str ] = {}
249250 if isinstance (job , ImageConversionJob | ThumbnailJob ):
250251 image , exif = result
251- if not isinstance (image , Image .Image ) or not isinstance (exif , Image .Exif ):
252+ if not isinstance (image [ 0 ] , Image .Image ) or not isinstance (exif , Image .Exif ):
252253 raise TypeError ("Fuck" )
253254 # apply format specific encoding options
254255 kwargs = {}
@@ -258,18 +259,30 @@ def write_and_upload_result(self, job: Job, result: "JobResult", filename: str)
258259 logger .debug (f"Format { job .mimetype } has custom encoding settings, kwargs is now: { kwargs } " )
259260 else :
260261 logger .debug (f"No custom settings for format { job .mimetype } " )
261- image .save (buf , format = job .filetype , exif = exif , ** kwargs )
262+ # sequence?
263+ if len (image ) > 1 :
264+ kwargs ["append_images" ] = image [1 :]
265+ kwargs ["save_all" ] = True
266+ image [0 ].save (buf , format = job .filetype , exif = exif , ** kwargs )
262267
263268 elif isinstance (job , ImageExifExtractionJob ):
264269 logger .debug (f"Got exif data { result } " )
265270 buf .write (json .dumps (result ).encode ())
266271
267272 elif isinstance (job , ThumbnailSourceJob ):
268273 image , exif = result
269- if not isinstance (image , Image .Image ) or not isinstance (exif , Image .Exif ):
274+ if not isinstance (image [ 0 ] , Image .Image ) or not isinstance (exif , Image .Exif ):
270275 raise TypeError ("Fuck" )
271- image .save (buf , format = "WEBP" , lossless = True , quality = 1 )
272- metadata = {"width" : 500 , "height" : image .height , "mimetype" : "image/webp" }
276+ kwargs = {}
277+ # thumbnailsources are always WEBP
278+ if "image/webp" in self .settings ["encoding" ]["images" ]:
279+ kwargs .update (self .settings ["encoding" ]["images" ]["image/webp" ])
280+ # sequence?
281+ if len (image ) > 1 :
282+ kwargs ["append_images" ] = image [1 :]
283+ kwargs ["save_all" ] = True
284+ image [0 ].save (buf , format = "WEBP" , ** kwargs )
285+ metadata = {"width" : 500 , "height" : image [0 ].height , "mimetype" : "image/webp" }
273286
274287 else :
275288 logger .error ("Unsupported job type" )
@@ -315,15 +328,11 @@ def handle_image_conversion_job(
315328
316329 logger .debug (f"Desired image size is { size } , aspect ratio: { ratio } ({ orig_str } ), converting image..." )
317330 start = time .time ()
318- # custom AR or not?
319- if job .custom_aspect_ratio :
320- image = ImageOps .fit (image = image , size = size , method = Image .Resampling .LANCZOS , centering = crop_center ) # type: ignore[assignment]
321- else :
322- image .thumbnail (size = size , resample = Image .Resampling .LANCZOS )
331+ images = transform_image (original_img = image , crop_w = size [0 ], crop_h = size [1 ])
323332 logger .debug (f"Converting image size and AR took { time .time () - start } seconds" )
324333
325334 logger .debug ("Done, returning result..." )
326- return image , exif
335+ return images , exif
327336
328337 def upload_job_result (
329338 self ,
0 commit comments