Ability to export only a selected region

Currently Krita lacks an ability to export a selected region.

It often needs some precise cropping to remove unwanted areas, to make the eyes stay easier on the important parts of the artwork.

Currently, I achieve that with a group layer, consisting an erase layer on top and a color filled layer at the bottom. Then I select the region of the erase layer and then copy and paste my whole work as a new file and then export.

The problem is that this is very resource intensive when I have a lot of layers. It takes time to copy the layers, and it doubles the memory use.

Update: Also I want to keep the whole workflow inside a single file, because switching from one file to each other takes some time, and it would be cumbersome if I am trying different crops or edits.

I found that there’s a plugin (GitHub - ollyisonit/krita-export-region: Krita plugin that allows you to export a selected region of a document.) that can achieve that and without the resource intensive part. However, the color of the exported images are a bit off. Changing the color profiles related settings does not work.

It would be great if someone fix the color issue of the plugin and then incorporate it into Krita.

2 Likes

You know… there is a filelayer.

  • Save your file.
  • Open a new file in the dimensions you need.
  • Add a file layer and select the saved file.
  • Move file layer as needed.

That workaround should help for the time being.

3 Likes

Nice idea with this file layer! I think this is excellent if you don’t want to commit to a specific crop as you keep working on your piece.

Maybe I’m misunderstanding the problem, but this issue seems contrived to me. I would also consider these methods:

  • select a rectangle area, copy merged and paste into a new image. This should have the same cost regardless of the layers
  • save a backup copy (you can close the document and work on that copy too), keep doing crop-undo until you are satisfied. Can also flatten first if it helps the performance.
1 Like

Thanks for the idea. It works. However, I would need to open a new file and I can’t edit a file layer directly.

Maybe I need to state more clearly that I want a solution that doesn’t need opening a separate file. Thank you!

:slight_smile: Hello @Oliver1, and welcome to the forum!

That is why @BeARToys added this remark:

The thing is, especially in the world of FOSS (Free and Open Source Software), where Krita belongs to, that it can take time for a solution to be implemented, so we try to offer at least workarounds for the time you have to wait for your feature.


But before a feature is considered worth implementing, interest must be shown in it. This means that the users should vote on this wish, especially you as the one who wants it, should cast your vote in your opening post to the left of your heading, because why work on a feature that nobody is interested in?
:wink:

Michelist

1 Like

Yeah I implemented an export that does this on one of my plugins because I was seriously tired of the current setup with exporting and lack of context sensitivity.

I have stopped using exports and only use save for KRA files now. It’s very limited but you really don’t need more.

You can check YetAnotherPlugin. It has a feature of exporting selection into a designated directory.

1 Like

An artboard like feature would indeed be nice

Hello,

I would

  • make a selection
  • ctrl c
  • ctrl shift n (new file from clipboard)
  • export
  • discard the new file from clipboard and back to my painting

If you want to copy all that is visible, not one layer, you can ctrl shift c.

+1 for this.

There are some workaround for sure, but sometimes I already have the local selection stored and I just want to use them for exporting…

Why not use this plugin for the time being? →

Michelist

The export of selected region can be achieved by using couple of Krita actions and a little bit of scripting:

import os
from datetime import datetime

from PyQt5 import QtWidgets

from krita import Krita


def timestamp():
    return datetime.now().strftime("%Y%m%d-%H%M%S-%f")[:-3]


def go():
    doc = Krita.instance().activeDocument()

    if doc is None:
        return

    selection = doc.selection()
    if selection:
        if selection.width() * selection.height() == 0:
            msg = "Seems that your selection is invalid."
            QtWidgets.QMessageBox.warning(None, "Warning", msg)
            return
    else:
        QtWidgets.QMessageBox.warning(None, "Warning", "No valid selection to export")
        return

    directory = str(
        QtWidgets.QFileDialog.getExistingDirectory(None, "Select Directory", "")
    )
    if not directory and not os.path.exists(directory):
        return

    w, h = selection.width(), selection.height()
    file_name = f"{timestamp()}-{w}-{h}.png"
    file_full_path = os.path.normpath(os.path.join(directory, file_name))

    Krita.instance().action("copy_merged").trigger()
    Krita.instance().action("paste_new").trigger()

    new_doc = Krita.instance().activeDocument()
    new_doc.setBatchmode(True)
    new_doc.saveAs(file_full_path)
    new_doc.waitForDone()
    new_doc.close()
    new_doc.waitForDone()
    new_doc.setBatchmode(False)


go()

The drawback is obviously the need to choose the directory all the time. This can be avoided by hardcoding the path in the variable directly. Actuators Variables and Sequences can help with tediousness.

Here the example: https://augmentedbrush.com/export-selection-to-a-file-with-actuator/

1 Like