extract_metadata: remove base64 data from metadata

The previously deprecated "data" field has now been removed. The "size" field now reports the size of the png.  Clients may use the "relative_path" field to retrieve thumbnail png files.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-21 16:55:19 -04:00 committed by Eric Callahan
parent c40c202220
commit db0eb8f22b
1 changed files with 15 additions and 23 deletions

View File

@ -249,7 +249,7 @@ class PrusaSlicer(BaseSlicer):
f.write(base64.b64decode(data.encode())) f.write(base64.b64decode(data.encode()))
parsed_matches.append({ parsed_matches.append({
'width': info[0], 'height': info[1], 'width': info[0], 'height': info[1],
'size': info[2], 'data': data, 'size': os.path.getsize(thumb_path),
'relative_path': rel_thumb_path}) 'relative_path': rel_thumb_path})
return parsed_matches return parsed_matches
@ -372,28 +372,20 @@ class Cura(PrusaSlicer):
# read file # read file
thumbs = [] thumbs = []
try: try:
with open(thumb_path, 'rb') as thumb_file: with Image.open(thumb_path) as im:
fbytes = thumb_file.read() thumbs.append({
with Image.open(io.BytesIO(fbytes)) as im: 'width': im.width, 'height': im.height,
thumb_full_b64 = base64.b64encode(fbytes).decode() 'size': os.path.getsize(thumb_path),
thumbs.append({ 'relative_path': rel_path_full
'width': im.width, 'height': im.height, })
'size': len(thumb_full_b64), 'data': thumb_full_b64, # Create 32x32 thumbnail
'relative_path': rel_path_full im.thumbnail((32, 32), Image.ANTIALIAS)
}) im.save(thumb_path_small, format="PNG")
# Create 32x32 thumbnail thumbs.insert(0, {
im.thumbnail((32, 32), Image.ANTIALIAS) 'width': im.width, 'height': im.height,
tmp_thumb = io.BytesIO() 'size': os.path.getsize(thumb_path_small),
im.save(tmp_thumb, format="PNG") 'relative_path': rel_path_small
im.save(thumb_path_small, format="PNG") })
thumb_small_b64 = base64.b64encode(
tmp_thumb.getbuffer()).decode()
tmp_thumb.close()
thumbs.insert(0, {
'width': im.width, 'height': im.height,
'size': len(thumb_small_b64), 'data': thumb_small_b64,
'relative_path': rel_path_small
})
except Exception as e: except Exception as e:
log_to_stderr(str(e)) log_to_stderr(str(e))
return None return None