Last active
August 29, 2015 14:09
-
-
Save ravikiranj/74e5e61d09a7b4002e25 to your computer and use it in GitHub Desktop.
Draw Lines on top of an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# sudo apt-get install python-pygame | |
import pygame | |
from os.path import basename | |
def drawCoordinates(filepath, coordinates): | |
# Load image | |
surface = pygame.image.load(filepath) | |
# Convert and preserve alpha values so that colors make sense | |
surface = surface.convert_alpha() | |
# Params | |
isClosed = 2 | |
thickness = 4 | |
color = pygame.Color("#589442") | |
# Draw lines | |
pygame.draw.lines(surface, color, isClosed, coordinates, thickness) | |
# Write file | |
opFileName = basename(filename).split(".")[0] + "_line.png" | |
pygame.image.save(surface, opFileName) | |
if __name__ == "__main__": | |
filename = "./560x1460.png" | |
# Dummy code to initialize pygame display | |
pygame.display.set_mode((1, 1)) | |
coordinates = [(200, 200), (200, 500), (400, 500), (400, 200)] | |
drawCoordinates(filename, coordinates) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment