Draws the image. If position is none, sets x and y to the origin. If w or h is defined, then scale the image to fit.
(self, path, p=None, alpha=1, pageNumber=None, w=None, h=None,
scaleType=None, clipPath=None)
| 951 | return '%s/%s-%sx%s.%s' % (path0, pre, w, h, ext), ext |
| 952 | |
| 953 | def image(self, path, p=None, alpha=1, pageNumber=None, w=None, h=None, |
| 954 | scaleType=None, clipPath=None): |
| 955 | """Draws the image. If position is none, sets x and y to the origin. If |
| 956 | w or h is defined, then scale the image to fit.""" |
| 957 | |
| 958 | # TODO: check valid extensions. |
| 959 | if p is None: |
| 960 | p = 0, 0 |
| 961 | |
| 962 | x, y = self.translatePoint(p) |
| 963 | |
| 964 | doScale = w is not None or h is not None |
| 965 | |
| 966 | if doScale: |
| 967 | if self.hasPIL: |
| 968 | path = self.scaleImage(path, w, h) |
| 969 | |
| 970 | # Now open the image in Flat. |
| 971 | img = self.b.image.open(path) |
| 972 | else: |
| 973 | # Missing PIL, slow scaling in Flat instead. |
| 974 | img.resize(width=w, height=h) |
| 975 | |
| 976 | else: |
| 977 | # TODO: slow Flat scale without PIL. |
| 978 | img = self.b.image.open(path) |
| 979 | w = img.width |
| 980 | h = img.height |
| 981 | |
| 982 | # Also scales frame width and height. |
| 983 | w, h = self.getScaledWH(w, h) |
| 984 | |
| 985 | # Now subtract the image height. |
| 986 | y -= h |
| 987 | placed = self.page.place(img) |
| 988 | placed.frame(x, y, w, h) |
| 989 | #self.restore() |
| 990 | |
| 991 | ''' |
| 992 | # Enable this for debugging. |
| 993 | xpt, ypt = point2D(upt(p)) |
| 994 | self.marker(xpt, ypt) |
| 995 | self.stroke((1, 0, 0)) |
| 996 | self.fill(None) |
| 997 | self.rect(xpt, ypt, w.pt, h.pt) |
| 998 | ''' |
| 999 | |
| 1000 | def imagePixelColor(self, path, p): |
| 1001 | return self.b.imagePixelColor(path, p) |
no test coverage detected