7288/7290 refactor out crop_percentage_to_pixel
trivial wrapper for crop_percentage_to_subpixel
This commit is contained in:
parent
a8a38ff87d
commit
460e631e5b
@ -57,6 +57,9 @@ def crop_percentage_to_subpixel(width, height, crop):
|
|||||||
crop[2]/100.0*width,
|
crop[2]/100.0*width,
|
||||||
crop[3]/100.0*height )
|
crop[3]/100.0*height )
|
||||||
|
|
||||||
|
def crop_percentage_to_pixel(width, height, crop):
|
||||||
|
return map (int, crop_percentage_to_subpixel(width, height, crop))
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# resize_to_jpeg
|
# resize_to_jpeg
|
||||||
@ -83,12 +86,9 @@ def resize_to_jpeg(source, destination, width, height, crop=None):
|
|||||||
img = gtk.gdk.pixbuf_new_from_file(source)
|
img = gtk.gdk.pixbuf_new_from_file(source)
|
||||||
|
|
||||||
if crop:
|
if crop:
|
||||||
# Gramps cropping coorinates are [0, 100], so we need to convert to pixels
|
(start_x, start_y, end_x, end_y
|
||||||
start_x = int((crop[0]/100.0)*img.get_width())
|
) = crop_percentage_to_pixel(
|
||||||
start_y = int((crop[1]/100.0)*img.get_height())
|
img.get_width(), img.get_height(), crop)
|
||||||
end_x = int((crop[2]/100.0)*img.get_width())
|
|
||||||
end_y = int((crop[3]/100.0)*img.get_height())
|
|
||||||
|
|
||||||
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
||||||
|
|
||||||
# Need to keep the ratio intact, otherwise scaled images look stretched
|
# Need to keep the ratio intact, otherwise scaled images look stretched
|
||||||
@ -214,12 +214,9 @@ def resize_to_buffer(source, size, crop=None):
|
|||||||
img = gtk.gdk.pixbuf_new_from_file(source)
|
img = gtk.gdk.pixbuf_new_from_file(source)
|
||||||
|
|
||||||
if crop:
|
if crop:
|
||||||
# Gramps cropping coorinates are [0, 100], so we need to convert to pixels
|
(start_x, start_y, end_x, end_y
|
||||||
start_x = int((crop[0]/100.0)*img.get_width())
|
) = crop_percentage_to_pixel(
|
||||||
start_y = int((crop[1]/100.0)*img.get_height())
|
img.get_width(), img.get_height(), crop)
|
||||||
end_x = int((crop[2]/100.0)*img.get_width())
|
|
||||||
end_y = int((crop[3]/100.0)*img.get_height())
|
|
||||||
|
|
||||||
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
|
||||||
|
|
||||||
# Need to keep the ratio intact, otherwise scaled images look stretched
|
# Need to keep the ratio intact, otherwise scaled images look stretched
|
||||||
|
Loading…
Reference in New Issue
Block a user