diff --git a/src/ImgManip.py b/src/ImgManip.py index f5fb624ed..5ce6529a5 100644 --- a/src/ImgManip.py +++ b/src/ImgManip.py @@ -46,6 +46,17 @@ import tempfile #------------------------------------------------------------------------- import Utils +def crop_percentage_to_subpixel(width, height, crop): + """ + Convert from Gramps cropping coordinates [0, 100] to + pixels, given image width and height. No rounding to pixel resolution. + """ + return ( + crop[0]/100.0*width, + crop[1]/100.0*height, + crop[2]/100.0*width, + crop[3]/100.0*height ) + #------------------------------------------------------------------------- # # resize_to_jpeg diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py index 133d84461..453eaf4b7 100644 --- a/src/plugins/docgen/ODFDoc.py +++ b/src/plugins/docgen/ODFDoc.py @@ -1025,12 +1025,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): pos = pos.title() if pos in ['left', 'right', 'single'] else 'Row' if crop: - # Gramps cropping coordinates are [0, 100], so we need to convert to pixels - # No rounding here, would lead to unwanted effects. - start_x = crop[0]/100.0*x - start_y = crop[1]/100.0*y - end_x = crop[2]/100.0*x - end_y = crop[3]/100.0*y + (start_x, start_y, end_x, end_y + ) = ImgManip.crop_percentage_to_subpixel(x, y, crop) # Need to keep the ratio intact, otherwise scaled images look stretched # if the dimensions aren't close in size