7288/7290 refactor out crop_percentage_to_subpixel

This commit is contained in:
Vassilii Khachaturov 2013-12-12 17:58:14 +02:00
parent 0d61bb01ab
commit a8a38ff87d
2 changed files with 13 additions and 6 deletions

View File

@ -46,6 +46,17 @@ import tempfile
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Utils 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 # resize_to_jpeg

View File

@ -1025,12 +1025,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
pos = pos.title() if pos in ['left', 'right', 'single'] else 'Row' pos = pos.title() if pos in ['left', 'right', 'single'] else 'Row'
if crop: if crop:
# Gramps cropping coordinates are [0, 100], so we need to convert to pixels (start_x, start_y, end_x, end_y
# No rounding here, would lead to unwanted effects. ) = ImgManip.crop_percentage_to_subpixel(x, y, crop)
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
# Need to keep the ratio intact, otherwise scaled images look stretched # Need to keep the ratio intact, otherwise scaled images look stretched
# if the dimensions aren't close in size # if the dimensions aren't close in size