Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to SVG with opacity on items #3017

Open
ElpadoCan opened this issue May 2, 2024 · 0 comments
Open

Export to SVG with opacity on items #3017

ElpadoCan opened this issue May 2, 2024 · 0 comments
Labels
enhancement exporters Issue relating to exporters svg

Comments

@ElpadoCan
Copy link
Contributor

ElpadoCan commented May 2, 2024

It would be very nice if the opacities of the items were respected when exporting to SVG.

Opacities are set with setOpacity method of the ImageItem (which very conveniently works with any other item).

Here is a minimal example where the resulting image is grey (black blended with white). However, the saved SVG is two images, one black and one white and the opacity of the white image is 100% (instead of 50% that was set in the code).

import numpy as np

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore

app = pg.mkQApp("Blend images example")

## Create window with GraphicsView widget
w = pg.GraphicsView()
w.show()
w.resize(800,800)
w.setWindowTitle('Two images blended with opacity')

view = pg.ViewBox()
w.setCentralItem(view)

## lock the aspect ratio
view.setAspectLocked(True)

## Create image item
img1 = pg.ImageItem(np.zeros((200,200)))
img1.setLevels([0, 1])
view.addItem(img1)

## Create image item
img2 = pg.ImageItem(np.ones((200,200)))
img2.setLevels([0, 1])
view.addItem(img2)
img2.setOpacity(0.5)

## Set initial view bounds
view.setRange(QtCore.QRectF(0, 0, 200, 200))

if __name__ == '__main__':
    pg.exec()

Displayed image in the app:

image

Saved SVG:

test

@j9ac9k j9ac9k added svg enhancement exporters Issue relating to exporters labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement exporters Issue relating to exporters svg
Projects
None yet
Development

No branches or pull requests

2 participants