diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py index 6f29e92b6..aaa71437f 100644 --- a/src/docgen/AbiWord2Doc.py +++ b/src/docgen/AbiWord2Doc.py @@ -172,9 +172,13 @@ class AbiWordDoc(BaseDoc.BaseDoc): self.f.close() def add_photo(self,name,pos,x_cm,y_cm): + + try: + image = ImgManip.ImgManip(name) + (x,y) = image.size() + except: + return - image = ImgManip.ImgManip(name) - (x,y) = image.size() aspect_ratio = float(x)/float(y) if aspect_ratio > x_cm/y_cm: diff --git a/src/docgen/AbiWordDoc.py b/src/docgen/AbiWordDoc.py index 72b1bbcd2..d1bc15019 100644 --- a/src/docgen/AbiWordDoc.py +++ b/src/docgen/AbiWordDoc.py @@ -118,8 +118,11 @@ class AbiWordDoc(BaseDoc.BaseDoc): self.f.close() def add_photo(self,name,pos,x_cm,y_cm): - - image = ImgManip.ImgManip(name) + + try: + image = ImgManip.ImgManip(name) + except: + return (x,y) = image.size() aspect_ratio = float(x)/float(y) diff --git a/src/docgen/KwordDoc.py b/src/docgen/KwordDoc.py index 1d61e9756..57928e7dc 100644 --- a/src/docgen/KwordDoc.py +++ b/src/docgen/KwordDoc.py @@ -409,7 +409,11 @@ class KwordDoc(BaseDoc.BaseDoc): def add_photo(self,name,pos,x_cm,y_cm): - im = ImgManip.ImgManip(name) + try: + im = ImgManip.ImgManip(name) + except: + return + (x,y)= im.size() ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) diff --git a/src/docgen/LaTeXDoc.py b/src/docgen/LaTeXDoc.py index 831d73d22..1f165dd33 100644 --- a/src/docgen/LaTeXDoc.py +++ b/src/docgen/LaTeXDoc.py @@ -380,8 +380,13 @@ class LaTeXDoc(BaseDoc.BaseDoc): def add_photo(self,name,pos,x,y): """Add photo to report""" + + try: + pic = ImgManip.ImgManip(name) + except: + return + self.imagenum = self.imagenum + 1 - pic = ImgManip.ImgManip(name) picf = self.filename[:-4] + '_img' + str(self.imagenum) + '.eps' pic.eps_convert(picf) diff --git a/src/docgen/OpenOfficeDoc.py b/src/docgen/OpenOfficeDoc.py index fad69fcf7..e37dd23e9 100644 --- a/src/docgen/OpenOfficeDoc.py +++ b/src/docgen/OpenOfficeDoc.py @@ -358,9 +358,15 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): os.system ('/usr/bin/oowriter "$FILE" &') def add_photo(self,name,pos,x_cm,y_cm): - image = ImgManip.ImgManip(name) - (x,y) = image.size() - ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) + + # try to open the image. If the open fails, it probably wasn't + # a valid image (could be a PDF, or a non-image) + try: + image = ImgManip.ImgManip(name) + (x,y) = image.size() + ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) + except: + return if ratio < 1: act_width = x_cm diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py index 743088998..da73ad869 100644 --- a/src/docgen/PdfDoc.py +++ b/src/docgen/PdfDoc.py @@ -286,7 +286,11 @@ class PdfDoc(BaseDoc.BaseDoc): self.col = self.col + self.span def add_photo(self,name,pos,x_cm,y_cm): - img = ImgManip.ImgManip(name) + try: + img = ImgManip.ImgManip(name) + except: + return + x,y = img.size() ratio = float(x_cm)*float(y)/(float(y_cm)*float(x)) diff --git a/src/docgen/RTFDoc.py b/src/docgen/RTFDoc.py index b94452285..6c29f058d 100644 --- a/src/docgen/RTFDoc.py +++ b/src/docgen/RTFDoc.py @@ -324,7 +324,11 @@ class RTFDoc(BaseDoc.BaseDoc): # #-------------------------------------------------------------------- def add_photo(self,name,pos,x_cm,y_cm): - im = ImgManip.ImgManip(name) + try: + im = ImgManip.ImgManip(name) + except: + return + nx,ny = im.size() ratio = float(x_cm)*float(ny)/(float(y_cm)*float(nx)) diff --git a/src/plugins/Ancestors.py b/src/plugins/Ancestors.py index 1cb38f376..ec08c791d 100644 --- a/src/plugins/Ancestors.py +++ b/src/plugins/Ancestors.py @@ -329,9 +329,10 @@ class ComprehensiveAncestorsReport (Report.Report): (partner != from_family_father and partner != from_family_mother)): for photo in partner.getPhotoList ()[:1]: - spouse.append ((self.doc.add_photo, - [photo.ref.getPath (), - 'right', 2, 2])) + if photo.getMimeType()[0:5] == "image": + spouse.append ((self.doc.add_photo, + [photo.ref.getPath (), + 'right', 2, 2])) if suppress_children and len (already_described): style = "AR-Child" @@ -359,8 +360,9 @@ class ComprehensiveAncestorsReport (Report.Report): else: ret.append ((self.doc.start_cell, ["AR-Photo"])) for photo in photos[:1]: - ret.append ((self.doc.add_photo, - [photo.ref.getPath (), 'left', 2, 2])) + if photo.getMimeType()[0:5] == "image": + ret.append ((self.doc.add_photo, + [photo.ref.getPath (), 'left', 2, 2])) ret.append ((self.doc.end_cell, [])) ret.append ((self.doc.start_cell, ["AR-Entry"])) diff --git a/src/plugins/DetAncestralReport.py b/src/plugins/DetAncestralReport.py index f3c67ed05..7355cad29 100644 --- a/src/plugins/DetAncestralReport.py +++ b/src/plugins/DetAncestralReport.py @@ -564,15 +564,17 @@ class DetAncestorReport(Report.Report): #-------------------------------------------------------------------- def insert_images(self, person, tag): - photos= person.getPhotoList() - for photo in photos : - attribs= photo.getAttributeList() - for attrib in attribs : - if attrib.getType() == tag: - vlist= string.split(attrib.getValue()) - if vlist[0] == 'left' or vlist[0] == 'right': - self.doc.add_photo(photo.ref.getPath(), vlist[0], \ - float(vlist[1]), float(vlist[2])) + photos= person.getPhotoList() + for photo in photos : + if photo.getMimeType()[0:5] != "image": + continue + attribs= photo.getAttributeList() + for attrib in attribs : + if attrib.getType() == tag: + vlist= string.split(attrib.getValue()) + if vlist[0] == 'left' or vlist[0] == 'right': + self.doc.add_photo(photo.ref.getPath(), vlist[0], \ + float(vlist[1]), float(vlist[2])) #-------------------------------------------------------------------- # @@ -584,6 +586,8 @@ class DetAncestorReport(Report.Report): photos= person.getPhotoList() numPhotos= 0 # Number of photos for photo in photos : + if photo.getMimeType()[0:5] != "image": + continue attribs= photo.getAttributeList() for attrib in attribs : if attrib.getType() == tag: diff --git a/src/plugins/DetDescendantReport.py b/src/plugins/DetDescendantReport.py index c8a671436..5bf7225bb 100644 --- a/src/plugins/DetDescendantReport.py +++ b/src/plugins/DetDescendantReport.py @@ -559,6 +559,8 @@ class DetDescendantReport(Report.Report): photos= person.getPhotoList() for photo in photos : + if photo.getMimeType()[0:5] != "image": + continue attribs= photo.getAttributeList() for attrib in attribs : if attrib.getType() == tag: @@ -577,6 +579,8 @@ class DetDescendantReport(Report.Report): photos= person.getPhotoList() numPhotos= 0 # Number of photos for photo in photos : + if photo.getMimeType()[0:5] != "image": + continue attribs= photo.getAttributeList() for attrib in attribs : if attrib.getType() == tag: