@@ -233,7 +233,7 @@ def encode_pil_to_base64(image):
233
233
# })
234
234
235
235
# Convert dict to bytes
236
- exif_bytes = piexif .dump (set_img_exif_dict ()) # Doesn't work here even though the exif is confirmed to have been added here
236
+ exif_bytes = piexif .dump (set_img_exif_dict ())
237
237
238
238
if opts .samples_format .lower () in ("jpg" , "jpeg" ):
239
239
image .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = opts .jpeg_quality )
@@ -249,7 +249,7 @@ def encode_pil_to_base64(image):
249
249
250
250
return base64 .b64encode (bytes_data )
251
251
252
- def export_pil_to_bytes (image , quality ):
252
+ def export_pil_to_bytes (image , quality , image_id = "" ):
253
253
with io .BytesIO () as output_bytes :
254
254
255
255
if opts .samples_format .lower () == 'png' :
@@ -262,10 +262,13 @@ def export_pil_to_bytes(image, quality):
262
262
image .save (output_bytes , format = "PNG" , pnginfo = (metadata if use_metadata else None ), quality = quality if quality else opts .jpeg_quality )
263
263
264
264
elif opts .samples_format .lower () in ("jpg" , "jpeg" , "webp" ):
265
- parameters = image .info .get ('parameters' , None )
266
- exif_bytes = piexif .dump ({
267
- "Exif" : { piexif .ExifIFD .UserComment : piexif .helper .UserComment .dump (parameters or "" , encoding = "unicode" ) }
268
- })
265
+ # parameters = image.info.get('parameters', None)
266
+ # exif_bytes = piexif.dump({
267
+ # "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(parameters or "", encoding="unicode") }
268
+ # })
269
+ # Convert dict to bytes
270
+ exif_bytes = piexif .dump (set_img_exif_dict (image_id = image_id ))
271
+
269
272
if opts .samples_format .lower () in ("jpg" , "jpeg" ):
270
273
image .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = quality if quality else opts .jpeg_quality )
271
274
else :
@@ -953,25 +956,25 @@ def post_invocations(self, b64images, quality):
953
956
image_id = datetime .datetime .now ().strftime (f"%Y%m%d%H%M%S-{ uuid .uuid4 ()} " )
954
957
suffix = opts .samples_format .lower ()
955
958
img = decode_to_image (b64image )
956
- if suffix in ("jpg" , "jpeg" ):
957
- # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_before")
958
- # print(img.getexif()) # Print the EXIF data
959
-
960
- # Save the image with the EXIF data
961
- exif_bytes = piexif .dump (set_img_exif_dict (image_id = image_id ))
962
- with io .BytesIO () as output_bytes :
963
- img .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = opts .jpeg_quality )
964
- output_bytes .seek (0 ) # Go back to the start of the BytesIO object
965
- img_after = Image .open (output_bytes )
966
- print (f"log@{ datetime .datetime .now ().strftime (f'%Y%m%d%H%M%S' )} GenID@{ user_input_data ['generation_id' ]} ***&&& post_invocations_after" )
967
- print (img_after .getexif ()) # Print the EXIF data
968
-
969
- bytes_data = export_pil_to_bytes (img , quality )
959
+ # if suffix in ("jpg", "jpeg"):
960
+ # # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_before")
961
+ # # print(img.getexif()) # Print the EXIF data
962
+ #
963
+ # # Save the image with the EXIF data
964
+ # exif_bytes = piexif.dump(set_img_exif_dict(image_id=image_id))
965
+ # with io.BytesIO() as output_bytes:
966
+ # img.save(output_bytes, format="JPEG", exif=exif_bytes, quality=opts.jpeg_quality)
967
+ # output_bytes.seek(0) # Go back to the start of the BytesIO object
968
+ # img_after = Image.open(output_bytes)
969
+ # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} GenID@{user_input_data['generation_id']} ***&&& post_invocations_after")
970
+ # print(img_after.getexif()) # Print the EXIF data
971
+ print ( f"log@ { datetime . datetime . now (). strftime ( f'%Y%m%d%H%M%S' ) } GenID@ { user_input_data [ 'generation_id' ] } image_id@ { image_id } " )
972
+ bytes_data = export_pil_to_bytes (img , quality , image_id = image_id )
970
973
# bytes_data = export_pil_to_bytes(decode_to_image(b64image), quality)
971
974
shared .s3_client .put_object (
972
975
Body = bytes_data ,
973
976
Bucket = bucket ,
974
- Key = f'{ key } /{ image_id } .{ suffix } ' ,
977
+ Key = f'{ key } /{ image_id } .{ suffix } ' # ,
975
978
# ExtraArgs={
976
979
# "ContentType": f"image/{suffix}"
977
980
# }
0 commit comments