I am working on an application to scale an image, but the bottom part of the image contains a special pattern that must be copied over and repeated since it is distorted during scaling. I have the following section of code:
In this code, I select and copy an area of size (width, 57) from coordinate (0,1479). Then, I scale the image to a new width. I then try and paste the selected area at coordinates (0,1479) and then at (original_width, 1479). So the whole of the bottom of the new image should have the original pattern. However, only a region on the bottom right of the image is covered, and not at the specified regions. In an example, if width was originally 25378, and then scaled to 31234, the selected area was only pasted onto the region from (15617,1479) to (31234,1479). The other area where I pasted first from (0,1479) to (15617,1479) has the distorted pattern after scaling and not the original pattern that was pasted onto it.
Can you please explain why this occurs, and suggest a way to properly copy and paste the original pattern onto the scaled image?
Thank you for your help!
Code:
image1 = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, Gio.file_new_for_path(image1_dir))
image1_width = image1.get_width()
image1.select_rectangle(Gimp.ChannelOps.REPLACE, 0, 1479, image1_width, 57)
image1_dr = image1.get_selected_drawables()
Gimp.edit_copy(image1_dr)
image.scale(image_new_width, image_height)
image1.select_rectangle(Gimp.ChannelOps.REPLACE, 0, 1479, image1_width, 57)
image1_dr = image1.get_selected_drawables()
Gimp.edit_paste(image1_dr[0], True)
image1.select_rectangle(Gimp.ChannelOps.REPLACE, image1_width, 1479, image1_width, 57)
image1_dr = image1.get_selected_drawables()
Gimp.edit_paste(image1_dr[0], True)
In this code, I select and copy an area of size (width, 57) from coordinate (0,1479). Then, I scale the image to a new width. I then try and paste the selected area at coordinates (0,1479) and then at (original_width, 1479). So the whole of the bottom of the new image should have the original pattern. However, only a region on the bottom right of the image is covered, and not at the specified regions. In an example, if width was originally 25378, and then scaled to 31234, the selected area was only pasted onto the region from (15617,1479) to (31234,1479). The other area where I pasted first from (0,1479) to (15617,1479) has the distorted pattern after scaling and not the original pattern that was pasted onto it.
Can you please explain why this occurs, and suggest a way to properly copy and paste the original pattern onto the scaled image?
Thank you for your help!