from ezgraphics import GraphicsImage, GraphicsWindow

GAP = 10
NUM_PICTURES = 20
MAX_WIDTH = 720

win = GraphicsWindow(MAX_WIDTH, 700)
canvas = win.canvas()

pic = GraphicsImage("picture1.gif")
canvas.drawImage(0, 0, pic)

x = 0
y = 0
maxY = 0
for i in range(2, NUM_PICTURES + 1) :
   maxY = max(maxY, pic.height())
   previous = pic
   filename = "picture%d.gif" % i
   pic = GraphicsImage(filename)
   x = x + previous.width() + GAP
   if x + pic.width() < MAX_WIDTH :
      canvas.drawImage(x, y, pic)
   else :
      x = 0
      y = y + maxY + GAP
      canvas.drawImage(x, y, pic)
    
win.wait()
##
#  This program processes a digital image by creating a negative of
#  the original.
#

from ezgraphics import GraphicsImage, GraphicsWindow

filename = input("Enter the name of the image file: ")

# Load the image from the file.
image = GraphicsImage(filename)

# Process the image.
width = image.width()
height = image.height()
for row in range(height):
    for col in range(width):
        # Get the current pixel color.
        red = image.getRed(row, col)
        green = image.getGreen(row, col)
        blue = image.getBlue(row, col)

        # Filter the pixel.
        newRed = 255 - red
        newGreen = 255 - green
        newBlue = 255 - blue

        # Set the pixel to the new color.
        image.setPixel(row, col, newRed, newGreen, newBlue)

# Display the image on screen.
Beispiel #3
0
# 4. Textbook R4.30, R.
# Given the flipImage.py program of Section 4.10
# change the code to flip the image horizontally instead of vertically

#  This program creates a new flipped version of a GIF image.
#
from ezgraphics import GraphicsImage, GraphicsWindow

filename = "queen-mary.gif"

# Load the original image.
origImage = GraphicsImage(filename)

# Create an empty image that will contain the new flipped image.
width = origImage.width()
height = origImage.height()
newImage = GraphicsImage(width, height)

# Iterate over the image and copy the pixels to the new image to
# produce the flipped image (vertical flip to an upside down image)
newRow = height - 1
for row in range(height):
    for col in range(width):
        newCol = col
        pixel = origImage.getPixel(row, col)
        newImage.setPixel(newRow, newCol, pixel)
    newRow = newRow - 1

# Save the new image with a new name.
newImage.save("flipped-" + filename)
Beispiel #4
0
from ezgraphics import GraphicsWindow
from ezgraphics import GraphicsImage
from math import sqrt
import os
'''
Use the os dir in order to save files at same folder
'''
__location__ = os.path.realpath(
    os.path.join(os.getcwd(), os.path.dirname(__file__)))
'''
Constructors
'''
picture = GraphicsImage(os.path.join(
    __location__, 'queen-mary.gif'))  #Change if you want another pic
#check size
if (picture.height() > picture.width()):
    WIDTH = picture.height()
    HEIGHT = picture.width()
else:
    HEIGHT = picture.height()
    WIDTH = picture.width()
#Find middle point
HeightRow = HEIGHT // 2
WidthCol = WIDTH // 2
newimage = GraphicsImage(WIDTH, HEIGHT)

#For future use
#To do : make a square pic
'''
Main function
'''