Tile and Slice Plug-in for Krita and Leaflet
The Krita plug-in for Leaflet in question is identical to the one I made for GIMP. I described the GIMP Leaflet plug-in in an earlier post. It takes an image, scales it up according to the zoom level in question, crops it so it's a perfect square and then starts slicing it into tiles.
The tiles themselves are used by JavaScript Leaflet library or whichever library that needs tiles, but Leaflet is supposed to be the reference. It saves the resulting tiles in a folder of your choice with a structure that you can use with Leaflet.
Krita has Python scripting support since version 4.0. It also uses QT to build an interface which can be made with PyQT.
I decided to port what I had in GIMP to Krita and learn something new along the way.
Since the original plug-in was made, there was one improvement requested where I added the maximum JPEG resolution possible. It's still a drain on the resources but that's the nature of the algorithm and you better not go that high if your machine can't support it. Roughly put, the maximum size of a single JPEG can be something like 16 GBs or so and it will kill your PC when it starts processing. Go easy on that. I somehow doubt the average user has a supercomputer.
You install it by extracting the contents of the folder to the: ~/.local/share/krita/pykrita on Linux distribution or in the current user's AppData\Roaming\krita\pykrita on Windows. If you're not sure which folder you are supposed to save the plug-in in, in Krita, in the menu bar, you can go to Settings -> Manage Resources and press the Open Resource Folder button in the following window. Make sure to restart Krita after you put the plug-in in the right place.
The contents look like this:
krita-leaflet |-- krita_leaflet | |-- __init__.py | |-- app.py | |-- krita_leaflet.py | `-- widget.py |-- krita_leaflet.desktop |-- LICENSE `-- README.rst
It's mostly Python code except the .desktop file which defines the plug-in metadata for Krita like an .ini file.
The module with __init__.py is important and expected to import the subclassed Extension from somewhere. It's all Python afterwards. Since libkis is a C++ library originally and it's just exposed in Python, the module can rely on getters, setters and camelCase. You have to live with that and ignore the PEP8 recommended syntax. It works, though.
The workflow is that you go to Tools -> Scripts -> Krita - Leaflet. It will work on the currently open flattened image. Pick the zoom level and the output folder and wait for it to finish. Depending on the zoom level you picked, you can go to lunch, have a coffee or something. The status bar of the resulting window is showing the current point it's at so you know it's working, but the algorithm has high complexity so be patient.
You can grab the Krita-Leaflet plug-in from the repo. Pull requests are, as always, welcome.