From ad1db164b8e0617b8f165349ccdfaa6fe1adde7f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 6 Feb 2002 05:34:34 +0000 Subject: [PATCH] EPS support for images svn: r756 --- gramps/src/GrampsParser.py | 15 +++++++----- gramps/src/ImgManip.py | 47 +++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/gramps/src/GrampsParser.py b/gramps/src/GrampsParser.py index c2c508131..b7c838b1a 100644 --- a/gramps/src/GrampsParser.py +++ b/gramps/src/GrampsParser.py @@ -159,22 +159,25 @@ class GrampsParser: self.count = self.count + 1 def start_location(self,attrs): + """Bypass the function calls for this one, since it appears to + take up quite a bit of time""" + loc = Location() if attrs.has_key('city'): - loc.set_city(u2l(attrs['city'])) + loc.city = u2l(attrs['city']) if attrs.has_key('parish'): - loc.set_parish(u2l(attrs['parish'])) + loc.parish = u2l(attrs['parish']) if attrs.has_key('state'): - loc.set_state(u2l(attrs['state'])) + loc.state = u2l(attrs['state']) if attrs.has_key('county'): - loc.set_county(u2l(attrs['county'])) + loc.county = u2l(attrs['county']) if attrs.has_key('country'): - loc.set_country(u2l(attrs['country'])) + loc.country = u2l(attrs['country']) if self.locations > 0: self.placeobj.add_alternate_locations(loc) else: self.placeobj.set_main_location(loc) - self.locations = self.locations + 1 + self.locations = self.locations + 1 def start_coord(self,attrs): if attrs.has_key('lat'): diff --git a/gramps/src/ImgManip.py b/gramps/src/ImgManip.py index 3dd51e8f4..743a1bc7e 100644 --- a/gramps/src/ImgManip.py +++ b/gramps/src/ImgManip.py @@ -86,11 +86,56 @@ class ImgManip: return buf else: im = PIL.Image.open(self.source) + if im.mode != 'RGB': + im.draft('RGB',im.size) + im = im.convert("RGB") return im.tostring("jpeg","RGB") + def eps_data(self): + if no_pil: + cmd = "%s '%s' 'eps:-'" % (const.convert,self.source) + r,w = popen2.popen2(cmd) + buf = r.read() + r.close() + w.close() + return buf + else: + import StringIO + + g = StringIO.StringIO() + im = PIL.Image.open(self.source) + im.save(g,"eps") + g.seek(0) + buf = g.read() + g.close() + return buf + + def eps_scale_data(self,x,y): + if no_pil: + cmd = "%s -geometry %dx%d '%s' 'eps:-'" % (const.convert,x,y,self.source) + r,w = popen2.popen2(cmd) + buf = r.read() + r.close() + w.close() + return buf + else: + import StringIO + + g = StringIO.StringIO() + im = PIL.Image.open(self.source) + im.thumbnail((width,height)) + if im.mode != 'RGB': + im.draft('RGB',im.size) + im = im.convert("RGB") + im.save(g,"eps") + g.seek(0) + buf = g.read() + g.close() + return buf + def png_scale_data(self,x,y): if no_pil: - cmd = "%s -geometry %dx%d'%s' 'jpg:-'" % (const.convert,x,y,self.source) + cmd = "%s -geometry %dx%d '%s' 'jpg:-'" % (const.convert,x,y,self.source) r,w = popen2.popen2(cmd) buf = r.read() r.close()