Skip to content

How to Zoom fitz.Pixmap to precise size #1048

Discussion options

You must be logged in to vote

Without going into Qt details (because I am not very acquainted with it, as I mostly using wxPython):

  • you want to make sure that the available area is best used by the page's pixmap: at least one of its width or height is exhausted
  • call the area's dimensions WIDTH, resp. HEIGHT, and the page's dimension width, resp height (i.e. page.rect.width, page.rect.height)
  • then compute the pixmap and the QImage like this
if width / height < WIDTH / HEIGHT:
    zoom = HEIGHT / height
else:
    zoom = WIDTH / width
mat = fitz.Matrix(zoom, zoom)
pix = page.getPixmap(matrix=mat, alpha=False)
qimg = QImage(pix.samples, pix.width, pix.height, pix.stride, QImage.Format_RGB888)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dmytro-balabukh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants