Skip to content

Commit

Permalink
Allow scaling images
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-del-Castillo committed Jan 4, 2022
1 parent 8b2054e commit 916c69d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pycture/editor/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,16 @@ def rotation_matrix(angle_rad: float):
new_image.setPixel(indexXp, indexYp, 0xffffff)
return new_image

def scale(self, size: (int, int), interpolation_technique):
return self
def scale(self, new_size: (int, int), interpolation_technique):
(new_width, new_height) = new_size
new_image = QImage(new_width, new_height, self.format())
actual_width = self.width()
actual_height = self.height()
width_ratio = new_width / actual_width
height_ratio = new_height / actual_height
for x in range(new_width):
actual_x = x / width_ratio
for y in range(new_height):
actual_y = y / height_ratio
new_image.setPixel(x, y, interpolation_technique(self, (actual_x, actual_y)))
return new_image

0 comments on commit 916c69d

Please sign in to comment.