Skip to content

Fix raster images added twice to SVG output#97

Closed
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/duplicate-raster-image
Closed

Fix raster images added twice to SVG output#97
leofernandezg wants to merge 1 commit intocdelker:masterfrom
leofernandezg:fix/duplicate-raster-image

Conversation

@leofernandezg
Copy link
Copy Markdown

Summary

  • Removes duplicate svgelements.append() call for raster images in the SVG backend

Problem

In schemdraw/backends/svg.py, the image() method appends raster image elements to self.svgelements twice:

  • Line 599: inside the else branch (raster images only)
  • Line 608: shared code path (all image types)

SVG images are only appended at line 608 (correct). Raster images get appended at both lines, resulting in every raster image appearing twice in the final SVG.

Changes

  • schemdraw/backends/svg.py: Remove the early self.svgelements.append() at line 599, keeping only the shared one at line 608
  • test/test_raster_image.py: New test verifying raster images appear exactly once

Test results

Without fix: Expected 1 image element, got 2
With fix: 1 passed

Fixes #92

The image() method in the SVG backend appended raster image elements
to svgelements twice: once before setting attributes (line 599) and
again at the shared exit point (line 608). SVG images were only
appended once, at the shared exit point, which was correct.

Remove the early append so raster images are added once, after all
attributes are set. Added test/test_raster_image.py to verify.

Fixes cdelker#92
@leofernandezg
Copy link
Copy Markdown
Author

Test suite results

Full test suite (py.test --nbval-lax test/) run on this branch produces the same results as master:

Branch Failed Passed
master (baseline) 38 432
this branch 38 433

The 38 pre-existing failures are in test_parselogic.ipynb and test_timing.ipynb (unrelated to this change).

@leofernandezg
Copy link
Copy Markdown
Author

Update: Re-ran the full test suite with all optional dependencies installed (matplotlib, ziamath, pyparsing).

Branch Passed Failed
master 470 0
fix/duplicate-raster-image 471 0

No regressions introduced.

@cdelker cdelker closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raster images added twice to SVG output

2 participants