Demo Draw Image

Download the image used: ludlow_1200x478.png

#! /usr/bin/python3
# ===================================================================
# display an image
# ===================================================================

import coordinate_conversion as cc
import transformation_matrix as tm
import user_interface as ui
from graphics import *
import numpy as np
import os, platform, sys

picture    = "ludlow_1200x478.png"
win_width  = 801
win_height = 801

# ---- create window

win = GraphWin("Image Demo", win_width, win_height)
win.setBackground("white")

ww = win.getWidth()
wh = win.getHeight()

print()
print(f'Win: width={ww} height={wh}')

# ---- create image

img = Image(Point(ww/2,wh*3/10),picture)

iw = img.getWidth()
ih = img.getHeight()

print()
print(f'Image: width={iw} height={ih}')

#---- create text message

msg = '''
This image (1200,478) is wider that the window (801,801).
It is truncated for display. A different Python package is
needed to scale the image to fit.
'''

txt = Text(Point(wh/2,wh*7/8),msg)

# ---- draw image and text

img.draw(win)
txt.draw(win)

# ---- pause, close window, and exit

ui.pause()
win.close()