2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2003 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#-------------------------------------------------------------------------
27
# Check for the python imaging library
29
#-------------------------------------------------------------------------
41
def __init__(self,source):
47
img = gtk.gdk.pixbuf_new_from_file(self.src)
48
return (img.get_width(),img.get_height())
50
def fmt_thumbnail(self,dest,width,height,cnv):
53
cmd = "%s -geometry %dx%d '%s' '%s:%s'" % (const.convert,w,h,self.src,cnv,dest)
56
def fmt_convert(self,dest,cnv):
57
cmd = "%s '%s' '%s:%s'" % (const.convert,self.src,cnv,dest)
60
def fmt_data(self,cnv):
61
cmd = "%s '%s' '%s:-'" % (const.convert,self.src,cnv)
62
r,w = popen2.popen2(cmd)
68
def fmt_scale_data(self,x,y,cnv):
69
cmd = "%s -geometry %dx%d '%s' '%s:-'" % (const.convert,x,y,self.src,cnv)
70
signal.signal (signal.SIGCHLD, signal.SIG_DFL)
71
r,w = popen2.popen2(cmd)
80
return PIL.Image.open(self.src).size
82
def fmt_thumbnail(self,dest,width,height,pil):
83
im = PIL.Image.open(self.src)
84
im.thumbnail((width,height))
86
im.draft('RGB',im.size)
87
im = im.convert("RGB")
88
im.save(dest,pil.upper())
90
def fmt_convert(self,dest,pil):
91
im = PIL.Image.open(self.src)
93
im.draft('RGB',im.size)
94
im = im.convert("RGB")
95
im.save(dest,pil.upper())
97
def fmt_data(self,pil):
98
g = StringIO.StringIO()
99
im = PIL.Image.open(self.src)
101
im.draft('RGB',im.size)
102
im = im.convert("RGB")
103
im.save(g,pil.upper())
109
def fmt_scale_data(self,x,y,pil):
110
im = PIL.Image.open(self.src)
113
im.draft('RGB',im.size)
114
im = im.convert("RGB")
115
return im.tostring(pil,"RGB")
117
def jpg_thumbnail(self,dest,width,height):
118
self.fmt_thumbnail(dest,width,height,"jpeg")
120
def png_thumbnail(self,dest,width,height):
121
self.fmt_thumbnail(dest,width,height,"png")
123
def eps_thumbnail(self,dest,width,height):
124
self.fmt_thumbnail(dest,width,height,"eps")
126
def jpg_convert(self,dest):
127
self.fmt_convert(dest,"jpeg")
129
def png_convert(self,dest):
130
self.fmt_convert(dest,"png")
132
def eps_convert(self,dest):
133
self.fmt_convert(dest,"eps")
136
return self.fmt_data("jpeg")
139
return self.fmt_data("png")
142
return self.fmt_data("eps")
144
def jpg_scale_data(self,x,y):
145
return self.fmt_scale_data(x,y,"jpeg")
147
def png_scale_data(self,x,y):
148
return self.fmt_scale_data(x,y,"png")
150
def eps_scale_data(self,x,y):
151
return self.fmt_scale_data(x,y,"eps")
154
if __name__ == "__main__":
158
img = ImgManip(sys.argv[1])
159
img.jpg_thumbnail("foo.jpg",50,50)
160
img.png_thumbnail("foo.png",50,50)
161
img.eps_thumbnail("foo.eps",50,50)