Skip to content

Commit 582b723

Browse files
committed
pdf backend support affine-transformed image
svn path=/trunk/matplotlib/; revision=8851
1 parent a59b6dc commit 582b723

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,14 +1386,41 @@ def merge_used_characters(self, other):
13861386
def get_image_magnification(self):
13871387
return self.image_dpi/72.0
13881388

1389-
def draw_image(self, gc, x, y, im):
1389+
def option_scale_image(self):
1390+
"""
1391+
pdf backend support arbitrary scaling of image.
1392+
"""
1393+
return True
1394+
1395+
def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
13901396
self.check_gc(gc)
13911397

13921398
h, w = im.get_size_out()
1393-
h, w = 72.0*h/self.image_dpi, 72.0*w/self.image_dpi
1399+
1400+
if dx is None:
1401+
w = 72.0*w/self.image_dpi
1402+
else:
1403+
w = dx
1404+
1405+
if dy is None:
1406+
h = 72.0*h/self.image_dpi
1407+
else:
1408+
h = dy
1409+
13941410
imob = self.file.imageObject(im)
1395-
self.file.output(Op.gsave, w, 0, 0, h, x, y, Op.concat_matrix,
1396-
imob, Op.use_xobject, Op.grestore)
1411+
1412+
if transform is None:
1413+
self.file.output(Op.gsave,
1414+
w, 0, 0, h, x, y, Op.concat_matrix,
1415+
imob, Op.use_xobject, Op.grestore)
1416+
else:
1417+
tr1, tr2, tr3, tr4, tr5, tr6 = transform.to_values()
1418+
1419+
self.file.output(Op.gsave,
1420+
tr1, tr2, tr3, tr4, tr5, tr6, Op.concat_matrix,
1421+
w, 0, 0, h, x, y, Op.concat_matrix,
1422+
imob, Op.use_xobject, Op.grestore)
1423+
13971424

13981425
def draw_path(self, gc, path, transform, rgbFace=None):
13991426
self.check_gc(gc, rgbFace)

0 commit comments

Comments
 (0)