{"id":9970,"library":"napari-svg","title":"Napari SVG Exporter","description":"napari-svg is a plugin for the napari viewer that enables exporting layers as SVG (Scalable Vector Graphics) files. It integrates directly into napari's file saving mechanism, allowing users to save their viewer's contents as vector graphics. The current version is 0.2.1, and being a napari plugin, its release cadence often aligns with napari's ecosystem updates, offering stability for its core functionality.","status":"active","version":"0.2.1","language":"en","source_language":"en","source_url":"https://github.com/napari/napari-svg","tags":["napari","plugin","svg","vector graphics","visualization","exporter"],"install":[{"cmd":"pip install napari-svg","lang":"bash","label":"Install plugin"}],"dependencies":[{"reason":"This is a napari plugin and requires napari to run.","package":"napari","optional":false},{"reason":"Required for array operations within napari.","package":"numpy","optional":false}],"imports":[],"quickstart":{"code":"import napari\nimport numpy as np\nimport os\n\n# Create a napari viewer\nviewer = napari.Viewer()\n\n# Add some sample data to visualize\nviewer.add_image(np.random.rand(100, 100), name='random_image')\nviewer.add_labels(np.zeros((100, 100), dtype=int), name='empty_labels')\nviewer.add_points(np.random.rand(10, 2) * 100, name='random_points')\nviewer.add_shapes(np.array([[20, 20], [20, 80], [80, 80], [80, 20]]), name='square_shape')\n\nprint(\"Napari viewer is running with sample data.\")\nprint(\"To save as SVG: In the napari GUI, go to 'File > Save Selected Layers As...' or 'File > Save All Layers As...'.\")\nprint(\"Then, select '.svg' as the file type and choose a filename. napari-svg will handle the export.\")\n\n# Example of attempting a programmatic save (requires napari-svg to be registered)\n# Note: GUI method is often more robust for plugins that register writers.\noutput_filename = 'napari_output.svg'\ntry:\n    # This attempts to use napari's internal writer selection based on extension\n    # The napari-svg plugin should be automatically detected if installed.\n    viewer.save(output_filename, selected=False) # Saves all layers\n    print(f\"Attempted programmatic save to '{output_filename}'. Check if file exists.\")\nexcept Exception as e:\n    print(f\"Programmatic save failed: {e}. The GUI method is generally more reliable for plugins.\")\n\n# Clean up the created file for demonstration purposes\n# if os.path.exists(output_filename):\n#     os.remove(output_filename)\n#     print(f\"Cleaned up '{output_filename}'.\")\n\nnapari.run()","lang":"python","description":"This quickstart demonstrates how to launch a napari viewer, add some sample layers, and then explains how to use the napari-svg plugin via the napari GUI's 'Save As...' dialog. The plugin automatically registers itself with napari's file writer system upon installation. While programmatic saving is also possible through `viewer.save()`, the GUI method ensures the plugin's writer is correctly invoked and provides direct user control over export options."},"warnings":[{"fix":"Be aware of this limitation when expecting pixel-perfect image or label representation. This plugin is best suited for vector-like layers (e.g., shapes, points). For raster data, consider taking screenshots or using other napari export methods.","message":"Image and label layers are not fully converted into vector graphics; they are represented as filled rectangles in the exported SVG.","severity":"gotcha","affected_versions":"All versions up to 0.2.1"},{"fix":"Avoid using text layers if SVG export is critical, or add text annotations manually to the SVG after export using a vector graphics editor.","message":"Text layers are currently not supported and will not be exported when saving to SVG using this plugin.","severity":"gotcha","affected_versions":"All versions up to 0.2.1"},{"fix":"Ensure napari is updated to `0.4.19` or newer (`pip install --upgrade napari`). Verify `napari-svg` is installed in the same environment as napari (`pip list | grep napari-svg`). Restart napari after installation.","message":"The napari-svg plugin may not be recognized by napari if `napari` is too old or if the plugin is not installed in the active Python environment.","severity":"gotcha","affected_versions":"<0.4.19"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Recognize that this plugin primarily handles vector-based layers (shapes, points) effectively. For raster data, consider taking a direct screenshot of the napari viewer or using other export methods designed for pixel-based output.","cause":"This is an intended limitation of the napari-svg plugin. It converts image and label layers into basic paths, causing them to appear as filled rectangles rather than detailed pixel data.","error":"SVG file is created, but images/labels are missing or appear as solid blocks."},{"fix":"Install the package using `pip install napari-svg`. Ensure you are running napari from the same environment where the plugin was installed. If using anaconda, activate the correct environment first.","cause":"The `napari-svg` package is not installed or not available in the current Python environment that napari is running in.","error":"ModuleNotFoundError: No module named 'napari_svg'"},{"fix":"1. Ensure `napari-svg` is installed (`pip install napari-svg`). 2. Update napari to a recent version (`pip install --upgrade napari`). 3. Restart napari after installation/update to allow plugin discovery.","cause":"The `napari-svg` plugin, which provides the SVG file writer, is either not installed, not correctly registered, or napari itself is too old.","error":"napari's 'Save As...' dialog does not show '.svg' as an option."}]}