Skip to content

Commit

Permalink
* change: add width/height parameters to draw_image()
Browse files Browse the repository at this point in the history
  • Loading branch information
royqh1979 committed May 9, 2020
1 parent 6d5df51 commit 816d1dd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ History
1.0.20
-----------
* add: Image.copy() method
* change: draw_image() add width/height parameters ( can copy image with scale)

1.0.19
-----------
Expand Down
12 changes: 8 additions & 4 deletions easygraphics/easygraphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,17 +1560,19 @@ def flood_fill(x: int, y: int, border_color, image: Image = None):
image.flood_fill(x, y, border_color)


def draw_image(x: int, y: int, src_image: Image, src_x: int = 0, src_y: int = 0, src_width: int = -1,
def draw_image(x: int, y: int, src_image: Image, width:int=0, height:int=0, src_x: int = 0, src_y: int = 0, src_width: int = -1,
src_height: int = -1, with_background=True, composition_mode=None, dst_image: Image = None):
"""
Copy part of the source image (src_image) to the destination image (dst_image).
Copy part of the source image (src_image) to the destination image (dst_image).
(x, y) specifies the top-left point in the destination image that is to be drawn onto.
(sx, sy) specifies the top-left point of the part in the source image that is to
(width, height) specifies the size of drawing part on the destination image.The default is (0, 0).
(src_x, src_y) specifies the top-left point of the part in the source image that is to
be drawn. The default is (0, 0).
(sw, sh) specifies the size of the part of the source image that is to be drawn.
(src_width, src_height) specifies the size of the part of the source image that is to be drawn.
The default, (0, 0) (and negative) means all the way to the bottom-right of the image.
if with_background is False, the source image's background will not be copied.
Expand All @@ -1582,6 +1584,8 @@ def draw_image(x: int, y: int, src_image: Image, src_x: int = 0, src_y: int = 0,
:param x: x coordinate value of the upper left point on the destination image
:param y: y coordinate value of the upper left point on the destination image
:param src_image: the source image to be copied
:param width: width of the drawing part on the destination image
:param height: height of the drawing part on the destination image
:param src_x: x coordinate value of the top-left point of of the part to be drawn
:param src_y: y coordinate value of the top-left point of of the part to be drawn
:param src_width: witdh of the top-left point of of the part to be drawn
Expand Down
25 changes: 20 additions & 5 deletions easygraphics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,17 +1307,19 @@ def fill_image(self, color):
self.fill_rect(-1, -1, self.get_width() + 2, self.get_height() + 2)
self.restore_settings()

def draw_image(self, x: int, y: int, image: "Image", src_x: int = 0, src_y: int = 0, src_width: int = 0,
def draw_image(self, x: int, y: int, image: "Image", width:int=0, height:int=0, src_x: int = 0, src_y: int = 0, src_width: int = 0,
src_height: int = 0, with_background=True, composition_mode=None):
"""
Copy part of the source image (src_image) to the destination image (dst_image).
(x, y) specifies the top-left point in the destination image that is to be drawn onto.
(sx, sy) specifies the top-left point of the part in the source image that is to
(width, height) specifies the size of drawing part on the destination image.The default is (0, 0).
(src_x, src_y) specifies the top-left point of the part in the source image that is to
be drawn. The default is (0, 0).
(sw, sh) specifies the size of the part of the source image that is to be drawn.
(src_width, src_height) specifies the size of the part of the source image that is to be drawn.
The default, (0, 0) (and negative) means all the way to the bottom-right of the image.
if with_background is False, the source image's background will not be copied.
Expand All @@ -1326,9 +1328,12 @@ def draw_image(self, x: int, y: int, image: "Image", src_x: int = 0, src_y: int
In the default mode (CompositionMode.SOURCE_OVER), the transparent background in the source
will not overwrite the destination.
:param x: x coordinate value of the upper left point on the destination image
:param y: y coordinate value of the upper left point on the destination image
:param image: the source image to be copied
:param width: width of the drawing part on the destination image
:param height: height of the drawing part on the destination image
:param src_x: x coordinate value of the top-left point of of the part to be drawn
:param src_y: y coordinate value of the top-left point of of the part to be drawn
:param src_width: witdh of the top-left point of of the part to be drawn
Expand All @@ -1342,8 +1347,18 @@ def draw_image(self, x: int, y: int, image: "Image", src_x: int = 0, src_y: int
old_mode = p.compositionMode()
p.setCompositionMode(composition_mode)
img = _prepare_image_for_copy(image, with_background)
p.drawImage(x, y, img, src_x, src_y, src_width, src_height)
self._mask_painter.fillRect(x, y, src_width, src_height, QtCore.Qt.color0)
if width<1 or height<1:
p.drawImage(x, y, img, src_x, src_y, src_width, src_height)
self._mask_painter.fillRect(x, y, src_width, src_height, QtCore.Qt.color0)
else:
if src_width<1:
src_width = img.width() - x
if src_height<1:
src_height = img.height() - y
target = QtCore.QRectF(x,y,width,height)
source = QtCore.QRectF(src_x,src_y,src_width,src_height)
p.drawImage(target,img,source)
self._mask_painter.fillRect(x, y, width, height, QtCore.Qt.color0)
if composition_mode is not None:
p.setCompositionMode(old_mode)
self._updated()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='easygraphics',
version='1.0.20',
version='1.0.20.1',
description='"A TC Graphics style like Graphics Library"',
long_description=readme + '\n\n' + history,
author='Roy Qu',
Expand Down

0 comments on commit 816d1dd

Please sign in to comment.