forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 233
/
test_full_page_image.py
55 lines (42 loc) · 1.62 KB
/
test_full_page_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from pathlib import Path
from fpdf import FPDF
from fpdf.image_parsing import get_img_info
from test.conftest import assert_pdf_equal
HERE = Path(__file__).resolve().parent
IMAGE_PATH = HERE / "png_images/ba2b2b6e72ca0e4683bb640e2d5572f8.png"
def test_full_width_image(tmp_path): # issue-166
img = get_img_info(IMAGE_PATH)
pdf = FPDF(format=(img["w"], img["h"]))
pdf.set_margin(0)
pdf.add_page()
pdf.image(IMAGE_PATH, w=img["w"])
assert_pdf_equal(pdf, HERE / "full_width_image.pdf", tmp_path)
def test_full_height_image(tmp_path): # issue-166
img = get_img_info(IMAGE_PATH)
pdf = FPDF(format=(img["w"], img["h"]))
pdf.set_margin(0)
pdf.add_page()
pdf.image(IMAGE_PATH, h=img["h"])
assert_pdf_equal(pdf, HERE / "full_height_image.pdf", tmp_path)
def test_full_pdf_width_image(tmp_path): # issue-528
pdf = FPDF()
pdf.set_margin(0)
pdf.add_page()
pdf.image(HERE / "png_images/ba2b2b6e72ca0e4683bb640e2d5572f8.png", w=pdf.epw)
assert_pdf_equal(pdf, HERE / "full_pdf_width_image.pdf", tmp_path)
def test_full_pdf_height_image(tmp_path): # issue-528
pdf = FPDF()
pdf.set_margin(0)
pdf.add_page()
pdf.image(HERE / "png_images/51a4d21670dc8dfa8ffc9e54afd62f5f.png", h=pdf.eph)
assert_pdf_equal(pdf, HERE / "full_pdf_height_image.pdf", tmp_path)
def test_image_with_explicit_dimensions(tmp_path):
pdf = FPDF()
pdf.set_margin(0)
pdf.add_page()
pdf.image(
HERE / "png_images/6c853ed9dacd5716bc54eb59cec30889.png",
w=pdf.epw,
dims=(500, 500),
)
assert_pdf_equal(pdf, HERE / "image_with_explicit_dimensions.pdf", tmp_path)