Skip to content

Instantly share code, notes, and snippets.

@mondalaci
Last active December 16, 2015 02:39
Show Gist options
  • Save mondalaci/5364335 to your computer and use it in GitHub Desktop.
Save mondalaci/5364335 to your computer and use it in GitHub Desktop.
Draw a red X on top of the supplied image.
#!/usr/bin/env python
# This is a simple command line image manipulation utility that draws a red X to the image.
import sys
import gtk
if len(sys.argv) != 3:
print 'usage: x-this-image source-image destination-image'
sys.exit()
source_filename = sys.argv[1]
destination_filename = sys.argv[2]
pixbuf = gtk.gdk.pixbuf_new_from_file(source_filename)
width = pixbuf.get_property('width')
height = pixbuf.get_property('height')
gtkwin = gtk.Window()
gtkwin.realize()
gdkwin = gtkwin.window
gc = gdkwin.new_gc()
red = gtk.gdk.Color(65535, 0, 0)
gc.set_foreground(red)
gc.set_rgb_fg_color(red)
gc.set_line_attributes(10, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
pixmap = gtk.gdk.Pixmap(gdkwin, width, height)
pixmap.draw_pixbuf(None, pixbuf, 0, 0, 0, 0)
pixmap.draw_line(gc, 0, 0, width-1, height-1)
pixmap.draw_line(gc, width-1, 0, 0, height-1)
pixbuf.get_from_drawable(pixmap, gdkwin.get_colormap(), 0, 0, 0, 0, width, height)
pixbuf.save(destination_filename, 'jpeg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment