Skip to content

Make it possible to output images - #1484

Open
almet wants to merge 1 commit into
mainfrom
output-images
Open

Make it possible to output images#1484
almet wants to merge 1 commit into
mainfrom
output-images

Conversation

@almet

@almet almet commented May 27, 2026

Copy link
Copy Markdown
Member

Fixes #629

@apyrgio

apyrgio commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

A couple of quick issues that I've encountered:

  1. If I select "Save safe PDFs to ..." and also select an image as an output, I get the following error:

    Traceback (most recent call last):
      File "/home/user/dangerzone/dangerzone/gui/main_window.py", line 1590, in start_button_clicked
        document.suffix = self.safe_extension.text()
        ^^^^^^^^^^^^^^^
      File "/home/user/dangerzone/dangerzone/document.py", line 146, in suffix
        raise errors.SuffixNotApplicableException()
    dangerzone.errors.SuffixNotApplicableException: Cannot set a suffix after setting an output filename
  2. While the "OCR document" checkbox is disabled, the language picker still works.

  3. The "Open safe documents after converting" option no longer works, because the list there includes PDF readers. For example, in my environment, MuPDF cannot open the produced PNG.

  4. The fact that -page-<N> is appended to the output should affect the "Save as" checkbox. This is necessary because we otherwise don't have a nice way to show in our UI where the sanitized files are stored.

  5. This feature applies to all selected files, regardless of their filetype. This means that if a user wants to sanitize multiple files in a directory, and keep images as images, they would need to sanitize the images first, and then the documents.

Most importantly though, I'm not sure if this feature solves #629 adequately. As a user of this tool, what I've wanted in several cases was a way to preserve the original file type. That is:

  • If I give you an image, please give me back an image. It doesn't have to be exact same file type (JPG/TIFF/etc), just a reasonably popular image format (here, PNG works great).
  • If I give you a document, give me back a PDF. Even if it's just a single page, since I may want OCR on it.

I have a feeling that this behavior could also be a default, but I'd like to know what you think here. We could of course have an option that converts everything to PDF, for advanced users who want the original behavior back. Finally, I think we can rework this PR to make this behavior possible, if we both like it. Very roughly:

  1. We could check the extension on the client side and the number of pages we get back. In case it's an image type and the number of pages is 1, it's probably an image type.
    • Ideally, once the server-side sends back the file type, we can ditch this heuristic.
  2. The safe document can be named document-safe.png, and we can communicate this in the Dangerzone UI.
  3. We can add an extra line for the application that will open PNG files, with the similar logic we have for PDF files.

@almet

almet commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

Thanks for the feedback!

If I give you an image, please give me back an image. It doesn't have to be exact same file type (JPG/TIFF/etc), just a reasonably popular image format (here, PNG works great); If I give you a document, give me back a PDF. Even if it's just a single page, since I may want OCR on it.

An interesting feature of being able to convert images to PDFs is the fact that it does OCR on them.

We probably want to have an interface that makes it possible to select the output format. We could have a dropdown with these options:

Format of the output document:

  • "Convert to images" ;
  • "Convert to PDF" (in which case we offer OCR options) ;
  • "Automatic detection" (the default), which will convert documents to PDFs, and images to images.

@apyrgio

apyrgio commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

We probably want to have an interface that makes it possible to select the output format. We could have a dropdown with these options:

Format of the output document:

  • "Convert to images" ;
  • "Convert to PDF" (in which case we offer OCR options) ;
  • "Automatic detection" (the default), which will convert documents to PDFs, and images to images.

I agree, if we want to be exhaustive we can offer three options. In that case though, if we know that something is an image, it's probably best to skip the -page-1 suffix altogether. But that's minor.

How do you want to handle this for this PR then? Also, I guess we're not considering it for inclusion in 0.11.0, right?

(Oh, btw, the option to convert to images could help with redactions btw, in the spirit of https://github.com/firstlookmedia/pdf-redact-tools)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Save Images as Images (instead of PDFs)

2 participants