[python] PyMuPDF 에서 해상도 올리기. PDF to IMG
How to Increase Image Resolution
https://pymupdf.readthedocs.io/en/latest/recipes-images.html
The image of a document page is represented by a Pixmap, and the simplest way to create a pixmap is via method Page.get_pixmap().
This method has many options to influence the result. The most important among them is the Matrix, which lets you zoom, rotate, distort or mirror the outcome.
Page.get_pixmap() by default will use the Identity matrix, which does nothing.
In the following, we apply a zoom factor of 2 to each dimension, which will generate an image with a four times better resolution for us (and also about 4 times the size):
zoom_x = 2.0 # horizontal zoom
zoom_y = 2.0 # vertical zoom
mat = fitz.Matrix(zoom_x, zoom_y) # zoom factor 2 in each dimension
pix = page.get_pixmap(matrix=mat) # use 'mat' instead of the identity matrix
dpi = 600
pix = page.get_pixmap(dpi)
Since version 1.19.2 there is a more direct way to set the resolution: Parameter "dpi" (dots per inch) can be used in place of "matrix". To create a 300 dpi image of a page specify pix = page.get_pixmap(dpi=300). Apart from notation brevity, this approach has the additional advantage that the dpi value is saved with the image file – which does not happen automatically when using the Matrix notation.
'프로그래밍 > Python' 카테고리의 다른 글
[python] pyttsx3, TTS, AudioBook, gTTS (0) | 2024.03.12 |
---|---|
[python] Pandas tutorial (0) | 2024.03.08 |
[python] djangorestframework 3.14.0 (0) | 2024.02.29 |
[python] Python 계단밟기 (0) | 2024.02.23 |
[python] Matplotlib Tutorial - 파이썬으로 데이터 시각화하기 (0) | 2024.02.23 |