stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

Saving paramters to exif as dict type

Open winterspringsummer opened this issue 3 years ago • 4 comments

  • Fixed handling (".jpg", ".jpeg", ".webp") files from 'images.py' Currently it gives only 'info' data if image is not png format, so when process images on extras tab above file types lose original parameters and saved only extras info. So I changed to give whole pnginfo as dict type which is converted to string.

  • Make 'get_image_info' function to handle exif data By referring to the existing logic, I changed it to a function and changed it to use it by calling it. It read exif data and if it is saved in dict type as string, convert to dict type and return it like same format as pnginfo. If exif has only parameters as general string, a function change it th dict with 'parameters' key. It's for already saved jpg images with general string.

  • Now, jpg files can store different parameters using dict type. image_info image_info2

winterspringsummer avatar Oct 29 '22 09:10 winterspringsummer

nice RCE

AUTOMATIC1111 avatar Oct 29 '22 11:10 AUTOMATIC1111

You should never use eval in general, especially in release codes anywhere. Rather consider ast.literal_eval for safety or re to save and parse.

aria1th avatar Oct 29 '22 11:10 aria1th

Thank you for telling me @aria1th . There's a lot I don't know about Python because I'm just learning it to add features I want while I use WebUI.

I changed eval function to ast.literal_eval and added import ast, @AUTOMATIC1111. I will be more careful when making pull requests.

winterspringsummer avatar Oct 29 '22 11:10 winterspringsummer

by changing startswith as dict type check as literal eval result, and using .update(another dict), this should be better. Currently raises exception when unexpected or invalid comments are in exif.

aria1th avatar Nov 04 '22 08:11 aria1th

I don't want to put JSON into JPEG comment field.

AUTOMATIC1111 avatar Jan 04 '23 14:01 AUTOMATIC1111