7288/7290: image cropping fixes in ODFDoc
Applied the patch from Matthias Basler attached to bug #7288, without the rename of x and y variables to minimize the diff. Code reviewed for correctness and retested manually. Further work needed (probably on the master branch only): 1) DPI default of 96 -- need to verify platform independence 2) Proper refactoring of the code into ODF-specific pieces and image manipulation that should go down into ImgManip.py
This commit is contained in:
@@ -1028,17 +1028,27 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
|
|
||||||
if crop:
|
if crop:
|
||||||
dpi = ImgManip.image_dpi(file_name)
|
dpi = ImgManip.image_dpi(file_name)
|
||||||
|
if not dpi:
|
||||||
|
dpi = (96.0,96.0) #LibOO 3.6 assumes this if image contains no DPI info
|
||||||
|
|
||||||
if dpi:
|
# 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
|
||||||
|
|
||||||
|
# Need to keep the ratio intact, otherwise scaled images look stretched
|
||||||
|
# if the dimensions aren't close in size
|
||||||
(act_width, act_height) = ImgManip.image_actual_size(
|
(act_width, act_height) = ImgManip.image_actual_size(
|
||||||
x_cm, y_cm, crop[2] - crop[0], crop[3] - crop[1]
|
x_cm, y_cm, int(end_x-start_x), int(end_y-start_y)
|
||||||
)
|
)
|
||||||
|
|
||||||
left = ((crop[0]/100.0)*x)/dpi[0]
|
# ODF wants crop measurements in inch.
|
||||||
right = (x - ((crop[2]/100.0)*x))/dpi[0]
|
left = start_x/dpi[0]
|
||||||
top = ((crop[1]/100.0)*y)/dpi[1]
|
right = (x - end_x)/dpi[0]
|
||||||
bottom = (y - ((crop[3]/100.0)*y))/dpi[1]
|
top = start_y/dpi[1]
|
||||||
|
bottom = (y - end_y)/dpi[1]
|
||||||
crop = (top, right, bottom, left)
|
crop = (top, right, bottom, left)
|
||||||
|
|
||||||
self.StyleList_photos.append(
|
self.StyleList_photos.append(
|
||||||
@@ -1046,8 +1056,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
pos += "_" + str(crop)
|
pos += "_" + str(crop)
|
||||||
else:
|
|
||||||
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
|
|
||||||
else:
|
else:
|
||||||
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
|
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user