feat(app): add image input support and bump to 1.5.0

Allow PNG/JPG/TIFF/BMP/GIF/WebP alongside PDF for preview and DXF conversion.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael-A-SloanandCursor committed 2026-09-03 17:05:17 -04:00
1 parent 19696937df
commit 2c9829ef8c
9 files changed
+88 -28

No files matched your search

+1 -1
View File
@@ -1,3 +1,3 @@
"""PDF to DXF converter application package."""
__version__ = "1.4.1"
__version__ = "1.5.0"
+5 -4
View File
@@ -13,6 +13,7 @@ import ezdxf
import fitz
from ezdxf import units
from app.input_document import open_input_document
from app.raster_vectorize import vectorize_page
@@ -142,13 +143,13 @@ def classify_page(
def classify_pdf_pages(
pdf_path: str | Path,
input_path: str | Path,
pages: list[int] | None = None,
*,
vector_threshold: int = 20,
) -> list[PageClassification]:
"""Classify selected pages of a PDF for the pre-convert review dialog."""
pdf = fitz.open(str(pdf_path))
"""Classify selected pages of a PDF or image for pre-convert review."""
pdf = open_input_document(input_path)
try:
indices = _page_indices(pdf, pages)
return [
@@ -1134,7 +1135,7 @@ def convert_pdf_to_dxf(
pdf_path = Path(pdf_path)
output_path = Path(output_path)
pdf = fitz.open(str(pdf_path))
pdf = open_input_document(pdf_path)
try:
indices = _page_indices(pdf, options.pages)
if not indices:
+45
View File
@@ -0,0 +1,45 @@
"""Open supported PDF and image inputs as PDF documents."""
from __future__ import annotations
from pathlib import Path
import fitz
PDF_EXTENSIONS = {".pdf"}
IMAGE_EXTENSIONS = {
".bmp",
".gif",
".jpeg",
".jpg",
".png",
".tif",
".tiff",
".webp",
}
SUPPORTED_EXTENSIONS = PDF_EXTENSIONS | IMAGE_EXTENSIONS
def is_image_input(path: str | Path) -> bool:
"""Return whether the selected input is a supported image."""
return Path(path).suffix.lower() in IMAGE_EXTENSIONS
def open_input_document(path: str | Path) -> fitz.Document:
"""Open a PDF directly or wrap an image in an in-memory PDF."""
input_path = Path(path)
extension = input_path.suffix.lower()
if extension not in SUPPORTED_EXTENSIONS:
supported = ", ".join(sorted(SUPPORTED_EXTENSIONS))
raise ValueError(f"Unsupported input type. Supported: {supported}")
document = fitz.open(str(input_path))
if extension in PDF_EXTENSIONS:
return document
try:
pdf_bytes = document.convert_to_pdf()
finally:
document.close()
return fitz.open("pdf", pdf_bytes)
+4 -1
View File
@@ -7,9 +7,12 @@ from pathlib import Path
import fitz
from PIL import Image
from app.input_document import open_input_document
def open_document(path: str | Path) -> fitz.Document:
return fitz.open(str(path))
"""Open a supported PDF or image for preview."""
return open_input_document(path)
def page_count(doc: fitz.Document) -> int:
+20 -10
View File
@@ -1,4 +1,4 @@
"""Main CustomTkinter UI for PDF to DXF conversion."""
"""Main CustomTkinter UI for PDF/image to DXF conversion."""
from __future__ import annotations
@@ -16,6 +16,7 @@ from app.converter import (
convert_pdf_to_dxf,
parse_page_range,
)
from app.input_document import IMAGE_EXTENSIONS, is_image_input
from app.page_review import ask_page_modes
from app.pdf_preview import close_document, open_document, page_count, render_page
@@ -27,7 +28,7 @@ ctk.set_default_color_theme("blue")
class App(ctk.CTk):
def __init__(self) -> None:
super().__init__()
self.title(f"PDF to DXF Converter v{__version__}")
self.title(f"PDF / Image to DXF Converter v{__version__}")
self.geometry("1100x720")
self.minsize(800, 520)
@@ -66,19 +67,19 @@ class App(ctk.CTk):
ctk.CTkLabel(
scroll,
text="PDF → DXF",
text="PDF / Image → DXF",
font=ctk.CTkFont(size=22, weight="bold"),
).pack(padx=16, pady=(16, 4), anchor="w", fill="x")
self._add_wrap_label(
scroll,
"Preview & convert for BricsCAD",
"Preview and convert drawings for BricsCAD",
font=ctk.CTkFont(size=12),
text_color=("gray40", "gray70"),
pady=(0, 12),
)
ctk.CTkButton(scroll, text="Open PDF…", command=self._open_pdf).pack(
ctk.CTkButton(scroll, text="Open PDF or Image…", command=self._open_pdf).pack(
padx=16, pady=6, fill="x"
)
@@ -220,7 +221,7 @@ class App(ctk.CTk):
self.preview_label = ctk.CTkLabel(
self.preview_frame,
text="Open a PDF to see a preview",
text="Open a PDF or image to see a preview",
text_color=("gray40", "gray60"),
)
self.preview_label.grid(row=0, column=0, sticky="nsew")
@@ -307,8 +308,16 @@ class App(ctk.CTk):
if self._busy:
return
path = filedialog.askopenfilename(
title="Open PDF",
filetypes=[("PDF files", "*.pdf"), ("All files", "*.*")],
title="Open PDF or Image",
filetypes=[
(
"PDF and image files",
"*.pdf *.png *.jpg *.jpeg *.tif *.tiff *.bmp *.gif *.webp",
),
("PDF files", "*.pdf"),
("Image files", " ".join(f"*{ext}" for ext in sorted(IMAGE_EXTENSIONS))),
("All files", "*.*"),
],
)
if not path:
return
@@ -319,7 +328,8 @@ class App(ctk.CTk):
self._page_index = 0
self.file_label.configure(text=self._pdf_path.name)
self._refresh_preview()
self._set_status(f"Loaded {page_count(self._doc)} page(s)")
input_kind = "image" if is_image_input(path) else "PDF"
self._set_status(f"Loaded {input_kind}: {page_count(self._doc)} page(s)")
except Exception as exc:
messagebox.showerror("Open failed", str(exc))
self._set_status("Failed to open PDF")
@@ -373,7 +383,7 @@ class App(ctk.CTk):
if self._busy:
return
if self._doc is None or self._pdf_path is None:
messagebox.showinfo("No PDF", "Open a PDF file first.")
messagebox.showinfo("No input", "Open a PDF or image file first.")
return
try: