Bug 418494 - Document.exportImage doesn't export from the current state of the document
Summary: Document.exportImage doesn't export from the current state of the document
Status: RESOLVED WORKSFORME
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: 4.2.8
Platform: Appimage Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-05 12:17 UTC by ioribranford
Modified: 2020-03-18 09:33 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Python script and kra for reproducing bug (490.35 KB, application/zip)
2020-03-05 12:17 UTC, ioribranford
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ioribranford 2020-03-05 12:17:12 UTC
Created attachment 126609 [details]
Python script and kra for reproducing bug

SUMMARY
When calling Document.exportImage, the exported image matches the document when it was opened, not the document in its current state. Any modifications made in script before the export do not apply.

STEPS TO REPRODUCE
1. Extract attachment files to home directory
2. Open Python script in Krita Scripter (opens kra, hides one layer and exports to png)
3. Run script
4. Open exported png

OBSERVED RESULT
The PNG image was exported with the hidden layer still visible

EXPECTED RESULT
The PNG image should be exported with the hidden layer invisible

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu Bionic

ADDITIONAL INFORMATION
- Workaround is to save, close, and reopen the document after modification and before export. Saving alone does not work.
- The exact same actions performed in the GUI work as expected.
Comment 1 Rebecca Breu 2020-03-05 19:22:50 UTC
I have this problem intermittently. Does calling "doc.waitForDone()" before the export reliably save the issue?
Comment 2 Rebecca Breu 2020-03-07 13:10:45 UTC
Disregard what I said above—I got confused.

I do in fact get the issue every time, and neither calling doc.waitForDone() nor time.sleep(3) before the export solves the problem, nor does disabling batch mode. So it doesn't seem to be a timing issue as far as I can tell. Saving and re-opening does seem to be the only "fix".
Comment 3 Halla Rempt 2020-03-18 09:33:29 UTC
Ah, you have to explicitly refresh the projection. This works for me:

from krita import *
doc = Krita.instance().openDocument('/home/boud/bug-exportImage/bug-exportImage.kra')
doc.setBatchmode(True)

for layer in doc.rootNode().childNodes():
    if layer.name() == "Layer 3": # has a drawing on it
        layer.setOpacity(0)
  
doc.refreshProjection()

''' Workaround for bug: save, close, reopen
doc.save()
doc.close()
doc = Krita.instance().openDocument('bug-exportImage.kra')
doc.setBatchmode(True)
'''

# BUG? exports from last opened state, instead of saved or current
# so without above workaround, drawing is still visible in png
doc.exportImage('bug-exportImage.png', InfoObject())

doc.close()