Skip to content

Commit

Permalink
fix: PNGExporter now exports to PNG instead of GIF
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
antscloud committed Nov 13, 2023
1 parent a1ee673 commit 81964bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fretboardgtr/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def export(self, to: Union[str, Path]) -> None:
tmp_file = Path(tmp_dir) / Path(f"{uuid.uuid4()}.svg")
self.drawing.saveas(str(tmp_file))
drawing = svg2rlg(str(tmp_file))
renderPM.drawToFile(drawing, str(to))
renderPM.drawToFile(drawing, str(to), fmt="PNG")


class PDFExporter(Exporter):
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ dev = [
"mypy",

# Python version capabilities
"six"


"six",

# Utils
"pypdf"
]

[tool.setuptools]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_exporters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import mimetypes
import tempfile
from pathlib import Path

import pytest
import svgwrite
from PIL import Image
from pypdf import PdfReader

from fretboardgtr.exporters import PDFExporter, PNGExporter, SVGExporter

Expand Down Expand Up @@ -31,6 +34,7 @@ def test_svg_exporter(drawing):
assert not outfile.exists()
svg_exporter.export(outfile)
assert outfile.exists()
assert mimetypes.guess_type(outfile)[0] == "image/svg+xml"


def test_png_exporter(drawing):
Expand All @@ -40,6 +44,9 @@ def test_png_exporter(drawing):
assert not outfile.exists()
png_exporter.export(outfile)
assert outfile.exists()
assert mimetypes.guess_type(outfile)[0] == "image/png"
img = Image.open(outfile)
assert img.format == "PNG"


def test_pdf_exporter(drawing):
Expand All @@ -49,3 +56,5 @@ def test_pdf_exporter(drawing):
assert not outfile.exists()
pdf_exporter.export(outfile)
assert outfile.exists()
assert mimetypes.guess_type(outfile)[0] == "application/pdf"
assert len(PdfReader(outfile).pages) == 1

0 comments on commit 81964bd

Please sign in to comment.