diff --git a/confluent_client/bin/nodeconsole b/confluent_client/bin/nodeconsole index 7e9dba50..36f21e21 100755 --- a/confluent_client/bin/nodeconsole +++ b/confluent_client/bin/nodeconsole @@ -257,10 +257,21 @@ def draw_image(data, width, height, doscale=True): errstr = 'Error rendering image:\n' + str(e) return draw_text(errstr, width, height) imgwidth, imgheight = get_pix_dimensions(width, height) - img = img.resize((imgwidth - 4, imgheight - 4)) - nimg = Image.new(mode='RGB', size=(img.width + 4, img.height + 4), color='black') + nimg = Image.new(mode='RGBA', size=(imgwidth, imgheight)) + imgwidth -= 4 + imgheight -= 4 + hscalefact = imgwidth / img.width + vscalefact = imgheight / img.height + if hscalefact < vscalefact: + rzwidth = imgwidth + rzheight = int(img.height * hscalefact) + else: + rzwidth = int(img.width * vscalefact) + rzheight = imgheight + img = img.resize((rzwidth, rzheight)) nd = ImageDraw.Draw(nimg) - nd.rectangle((0, 0, nimg.width - 1, nimg.height -1), outline='white', width=1) + nd.rectangle((1, 1, rzwidth + 2, rzheight + 2), outline='black', width=1) + nd.rectangle((0, 0, rzwidth + 3, rzheight + 3), outline='white', width=1) nimg.paste(img, box=(2, 2)) outfile = io.BytesIO() nimg.save(outfile, format='PNG')