Convert Mermaid Diagram to Image: High-Res Export Guide

2026-09-01 · 10 min · Mermaid / diagram export / high-resolution images / 300 DPI / scientific figures

If you need to convert Mermaid diagram to image, the best method depends on where the diagram will be used. A classroom slide, a homework submission, a journal manuscript, and a poster may all require different output formats, dimensions, and levels of control. Mermaid diagrams can be exported through the official command-line tool, the browser-based Live Editor, or a Mermaid-compatible extension inside a code editor.

The central quality decision is whether you need a vector file or a raster image. SVG is a vector format, so it can be enlarged without becoming blurry. For publication, SVG or a sufficiently large PNG is usually the safest choice. When a submission system asks for 300 DPI, remember that DPI is determined by pixel dimensions and physical size together: a figure that is 3 inches wide at 300 DPI needs to be 900 pixels wide.

Choose the right format before you convert Mermaid diagram to image

Before exporting, identify the destination rather than choosing a file type by habit. SVG is generally the strongest option when the submission system accepts it because its lines, labels, and shapes remain sharp at different display sizes. It is especially useful for flowcharts, sequence diagrams, architecture diagrams, and other graphics made from clean geometric elements. SVG is a vector format, which means that enlarging it does not introduce the pixelation associated with bitmap images.

PNG is a practical choice when a learning platform, slide application, document editor, or journal portal does not accept SVG. Its quality depends on the number of pixels in the exported image and the physical size at which the image will be placed. PDF can also be useful when a document workflow accepts it, particularly when preserving scalable diagram content matters. The official Mermaid command-line tool supports PNG, SVG, and PDF output.

For a research paper, export SVG when the submission instructions allow it, and keep a high-pixel PNG as a fallback. For slides, a PNG with enough pixels for the intended display width is often simpler. For homework, the most important concerns are readable labels, complete cropping, and compatibility with the required submission format.

  • Use SVG when you need scalable, sharp graphics and the destination accepts vector files.
  • Use PNG when broad compatibility is more important than infinite scalability.
  • Use PDF when the document workflow accepts PDF and you want a scalable export.
  • Check the destination’s technical requirements; for any specific limit or format rule, follow the official guide.

Export with the official Mermaid CLI

The official Mermaid command-line tool is @mermaid-js/mermaid-cli, and its command is mmdc. This is the most repeatable option when you need to export many diagrams, keep a documented workflow, or regenerate figures after editing the Mermaid source. Because the source remains plain text, you can store it with a paper, course project, or presentation and reproduce the image later.

The basic workflow is to provide a Mermaid input file and an output file. For example, a command can use mmdc with an input file such as diagram.mmd and an output file such as diagram.png. The output extension determines whether the result is PNG, SVG, or PDF. The official command-line tool supports -o for output, so an export can be directed to the required filename and format.

For pixel-based output, use -w and -H to specify the width and height in pixels. For example, an export intended to be 900 pixels wide can use -w 900. If you also need a controlled height, provide -H with the desired pixel value. Use -b to specify a background color; transparent can be used when a transparent background is required. A representative command is mmdc -i diagram.mmd -o diagram.png -w 900 -H 1200 -b transparent.

The CLI is particularly useful for academic work because the dimensions are explicit. You can place the command in project notes, a build script, or a lab record and later reproduce the same output. If your diagram changes, rerun the command instead of manually resizing an old image, which helps prevent inconsistent line thickness, cropping, and label scale across a set of figures.

  • Package: @mermaid-js/mermaid-cli.
  • Command: mmdc.
  • Output option: -o, with PNG, SVG, or PDF output supported.
  • Pixel dimensions: use -w for width and -H for height.
  • Background: use -b; transparent can produce a transparent background.

Use the Mermaid Live Editor for a fast browser workflow

The Mermaid Live Editor is convenient when you want to convert Mermaid diagram to image without setting up a local command-line workflow. Paste or write the Mermaid source, inspect the rendered preview, and use the editor’s export controls to obtain an image or document-friendly output. This approach is useful for students testing syntax, teachers preparing a quick visual, and researchers making a one-off figure.

The Live Editor is also helpful for visual checking. Before exporting, inspect whether labels wrap unexpectedly, whether connectors overlap text, and whether the diagram is too wide for the page or slide. A diagram that looks acceptable in a browser preview may still be too small when inserted into a manuscript, so judge the result at the approximate physical width where it will be used.

For a formal submission, do not rely only on the visual size of the preview. If the exported PNG must meet a stated pixel or resolution requirement, verify the resulting image dimensions with an image-information tool or your document workflow. If the editor does not give you the exact control required by a submission specification, use the CLI with explicit -w and -H values instead. Any platform-specific export behavior should be checked against the official guide.

  • Best for quick editing, previewing, and one-off exports.
  • Inspect text wrapping and connector placement before downloading.
  • Use SVG when the destination supports vector graphics.
  • Verify PNG pixel dimensions when a paper or portal specifies an image size.

Convert Mermaid diagram to image inside VS Code

A Mermaid-compatible VS Code extension can keep source editing and visual preview in the same workspace. This is a productive option when your diagrams already live beside code, documentation, experiment notes, or course files. You can edit the Mermaid text, open the preview, and use the extension’s available export action to create a file for a report or presentation.

The main advantage is context. A researcher can keep a diagram next to the methods or system description, while a student can submit the source file together with the rendered figure. A teacher can maintain a folder of lecture diagrams and update them without switching between several applications. This also makes it easier to track revisions and preserve the exact source used to create a figure.

Export controls differ between extensions, so do not assume that every extension provides identical file types, background controls, or pixel-dimension settings. Look for options related to PNG, SVG, PDF, width, height, scale, or background. If you need exact 300 DPI production settings, the CLI is usually the more transparent route because you can directly set pixel dimensions with -w and -H. For extension-specific behavior, follow the official guide for that extension.

  • Use a VS Code extension when source files and diagrams should stay in one project.
  • Preview the complete diagram before exporting, especially after text edits.
  • Check whether the extension exports PNG, SVG, or PDF.
  • Use the official guide for extension-specific commands and limitations.

Set up a 300 DPI PNG for a paper

A common mistake is treating DPI as a setting that exists independently of image size. For a bitmap image, DPI is determined by pixel dimensions and physical dimensions together. The calculation is straightforward: required pixels = physical size in inches × target DPI. Therefore, a figure that is 3 inches wide at 300 DPI needs 900 pixels wide.

If the intended printed width is 4 inches, the same calculation gives 1,200 pixels at 300 DPI. If the intended width is 6 inches, it requires 1,800 pixels. These are pixel-width targets; choose the height according to the diagram’s aspect ratio or the available page space. Avoid forcing an arbitrary height that distorts the diagram.

With the official CLI, you can request the necessary PNG width using -w. For the 3-inch example, an export could use mmdc -i diagram.mmd -o diagram.png -w 900. If you know the required height, add -H with the corresponding pixel value. The key is to decide the final physical width first, then calculate the pixel width instead of exporting a small image and enlarging it later.

For journal submission, check the journal’s official artwork instructions for accepted formats, color requirements, maximum dimensions, and any resolution rules. Do not assume that every journal uses the same definition of figure size or accepts the same file types. If the official guide permits SVG, it may be preferable because SVG is vector and does not lose sharpness when enlarged. If PNG is required, export at the needed pixel dimensions from the start.

  • Formula: pixel width = physical width in inches × DPI.
  • 3 inches × 300 DPI = 900 pixels wide.
  • 4 inches × 300 DPI = 1,200 pixels wide.
  • 6 inches × 300 DPI = 1,800 pixels wide.
  • Set PNG dimensions with -w and, when needed, -H.
  • For exact journal requirements, use the official guide.

Improve readability, spacing, and cropping before export

High resolution cannot repair a diagram that is structurally difficult to read. First simplify long labels, break complicated processes into logical groups, and avoid placing too many nodes in a narrow horizontal or vertical area. If the diagram is intended for a paper column, design it around that column width rather than creating a very wide graphic and shrinking it until the text becomes microscopic.

Check the rendered result at three scales: the full diagram, the final inserted size, and a close view of small labels. At the final inserted size, ask whether a reader can distinguish node text, arrow direction, and relationship labels without zooming. For lecture slides, test the figure from the back of the room if possible; for online homework, inspect it on both a laptop-sized display and a smaller screen.

Background choice also affects usability. A transparent background can work well when the figure must sit on a colored page or slide, and the CLI supports transparent through -b. A solid background is often safer when a submission system previews transparency incorrectly or when contrast depends on a consistent page color. Whichever option you choose, verify that thin lines and text remain visible against the final background.

  • Design for the final physical or screen size, not only the editor preview.
  • Avoid shrinking a wide diagram until labels become unreadable.
  • Check arrows, line crossings, node text, and relationship labels at final size.
  • Use a transparent background only after confirming that the destination handles it correctly.

Build a reliable export workflow for papers, classes, and slides

A dependable workflow separates the Mermaid source from the exported assets. Keep the .mmd source file, record the intended output format and dimensions, and use a consistent naming pattern such as figure-01.svg or figure-01-900px.png. This makes it clear which file is editable and which file is ready for insertion. It also prevents accidental submission of a low-resolution preview when a high-resolution export exists.

For a research project, export an SVG master and a PNG fallback when allowed. For a class assignment, retain the source so that formatting can be corrected without redrawing the figure. For teaching materials, create a version sized for the slide layout and a separate version for handouts if their physical dimensions differ. Do not repeatedly resize the same PNG for unrelated destinations; regenerate from the source at the needed dimensions.

Before delivery, run a final checklist. Confirm that the file opens, the entire diagram is present, the background is intentional, labels are readable, and the dimensions match the destination. If a portal rejects the file, check its official guide rather than guessing. Requirements for file type, maximum size, embedded fonts, color, or resolution vary by platform and publication.

  • Keep the Mermaid source and rendered files together.
  • Record the target format, physical width, pixel width, and intended use.
  • Export separate versions when paper, slides, and handouts need different sizes.
  • Preserve an SVG master when possible, plus a PNG fallback for compatibility.
  • For submission rules, use the official guide.

Preguntas sobre este diagrama

How do I convert Mermaid diagram to image as a PNG?

Use the official Mermaid command-line tool, @mermaid-js/mermaid-cli, with the mmdc command and an output filename ending in .png. You can set the pixel dimensions with -w and -H, for example mmdc -i diagram.mmd -o diagram.png -w 900. You can also export through the Mermaid Live Editor or a Mermaid-compatible VS Code extension.

Is SVG or PNG better for a Mermaid diagram in a paper?

SVG is a vector format, so it can be enlarged without becoming blurry and is often the better choice when the submission system accepts it. PNG is useful when the journal or document software requires a bitmap image, but its quality depends on pixel dimensions. Follow the journal’s official guide for the accepted format and resolution rules.

How many pixels do I need for 300 DPI?

Calculate pixels by multiplying the intended physical width in inches by 300. For example, a figure that is 3 inches wide at 300 DPI needs 900 pixels wide. Set the PNG width accordingly with the CLI’s -w option, and determine height from the diagram’s aspect ratio or the required layout.

Can I export a Mermaid diagram with a transparent background?

Yes. The official Mermaid CLI supports -b for the background color, and transparent can be used when you need a transparent background. Check the exported file in the final application because some document or submission systems may preview transparency differently. For platform-specific behavior, follow the official guide.

Herramientas relacionadas

Abrir el estudio y generar tu primer diagrama →

Más artículos