(→Painting) |
Neverendingo (Talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 16: | Line 16: | ||
===Scripting Handbook=== | ===Scripting Handbook=== | ||
| − | The [http://kross.dipe.org/dox/krita.html Krita Scripting Handbook] contains a full reference of | + | The [http://kross.dipe.org/dox/krita.html Krita Scripting Handbook] ([http://kross.dipe.org/dox/krita.pdf PDF]) contains a full reference of the functionality accessible from within the scripting backends. |
| − | The Handbook is generated from the sourcecode using doxygen and | + | The Handbook is generated from the sourcecode using doxygen and KWord's [[Development/Tutorials/KWord_Scripting#Import_combined_Doxygen_XML_File|Import Doxygen XML File]] python script. |
===Links=== | ===Links=== | ||
| Line 28: | Line 28: | ||
* [http://kross.dipe.org Kross Homepage] | * [http://kross.dipe.org Kross Homepage] | ||
* [http://wiki.koffice.org/index.php?title=Kross Kross Wiki Page] | * [http://wiki.koffice.org/index.php?title=Kross Kross Wiki Page] | ||
| − | |||
==Scripting Extensions== | ==Scripting Extensions== | ||
| Line 59: | Line 58: | ||
Most parts of the [http://websvn.kde.org/trunk/koffice/krita/plugins/viewplugins/scripting/scripts/pilimport.py?&view=markup pilimport.py] Python script are related to GUI and preparation of the import-proccess. The core part of that script, so the part that does actualy do the import, looks like; | Most parts of the [http://websvn.kde.org/trunk/koffice/krita/plugins/viewplugins/scripting/scripts/pilimport.py?&view=markup pilimport.py] Python script are related to GUI and preparation of the import-proccess. The core part of that script, so the part that does actualy do the import, looks like; | ||
| − | < | + | <syntaxhighlight lang="python"> |
# import needed modules and initialize PIL | # import needed modules and initialize PIL | ||
import Krita, Image, ImageFile | import Krita, Image, ImageFile | ||
| Line 84: | Line 83: | ||
it.next() | it.next() | ||
krtlayer.endPainting() | krtlayer.endPainting() | ||
| − | </ | + | </syntaxhighlight> |
The [http://websvn.kde.org/trunk/koffice/krita/plugins/viewplugins/scripting/scripts/pilexport.py?&view=markup pilexport.py] Python script which does export a Krita image to a by the Python Imaging Library supported image-format looks then like; | The [http://websvn.kde.org/trunk/koffice/krita/plugins/viewplugins/scripting/scripts/pilexport.py?&view=markup pilexport.py] Python script which does export a Krita image to a by the Python Imaging Library supported image-format looks then like; | ||
| − | < | + | <syntaxhighlight lang="python"> |
# import needed modules and initialize PIL | # import needed modules and initialize PIL | ||
import Krita, Image, ImageFile | import Krita, Image, ImageFile | ||
| Line 107: | Line 106: | ||
# and save the result | # and save the result | ||
pilimage.save("/home/user/myimage.jpg") | pilimage.save("/home/user/myimage.jpg") | ||
| − | </ | + | </syntaxhighlight> |
===Painting=== | ===Painting=== | ||
Krita Scripting
Contents |
Krita is a painting and image editing application for KOffice.
Krita comes with a bunch of plugins where the scripting plugin uses the Kross scripting framework to offer powerful scripting with Python, Ruby and KDE JavaScript.
The plugin consist of following parts;
The Krita Scripting Handbook (PDF) contains a full reference of the functionality accessible from within the scripting backends.
The Handbook is generated from the sourcecode using doxygen and KWord's Import Doxygen XML File python script.
Extensions are used to extend Krita with additional functionality written in Python, Ruby or KDE JavaScript scripts.
The following screenshot shows Krita running with it's on the right half displayed scripting-docker that is used to display scripts and fastly execute scripts. The image itself was created using the Random painting Ruby script.
Those extensions are also accessible from within the "Scripts"-menu and are distributed with Krita, so some default extensions are installed together with Krita as part of it, or could be later added and configured on demand using the "Script Manager".
Following sections try to provide an overview of the per default with Krita distributed scripting extensions.
The both scripts pilimport.py and pilexport.py are using the Python Imaging Library to import and export to the by PIL support image-formats.
The following screenshot shows the "Python Imaging Library Import" Python script pilimport.py once executed.
For GUI-related things you are also able to use PyQt4 or Tkinter in your python scripts, Korundum/QtRuby in your Ruby scripts, KjsEmbed4 (KjsEmbded4 is included in kdelibs4 now) in your JavaScript scripts or the more high-level Kross forms in all interpreter-backends.
Most parts of the pilimport.py Python script are related to GUI and preparation of the import-proccess. The core part of that script, so the part that does actualy do the import, looks like;
# import needed modules and initialize PIL import Krita, Image, ImageFile Image.init() # read the imagefile and convert to RGB pilimage = Image.open("/home/user/myimage.jpg") pilimage = pilimage.convert("RGB") # fetch the Krita layer we like to import to krtlayer = Krita.image().activePaintLayer() # scale the loaded image to fit pilimage = pilimage.resize( (krtlayer.width(), krtlayer.height())) # let's use the progressbar Krita.progress().setProgressTotalSteps( krtlayer.width() * krtlayer.height()) # finally do the import krtlayer.beginPainting("PIL import") it = krtlayer.createRectIterator( 0, 0, krtlayer.width(), krtlayer.height()) while (not it.isDone()): data = pilimage.getpixel((it.x(), it.y())) it.setPixel(list(data)) Krita.progress().incProgress() it.next() krtlayer.endPainting()
The pilexport.py Python script which does export a Krita image to a by the Python Imaging Library supported image-format looks then like;
# import needed modules and initialize PIL import Krita, Image, ImageFile Image.init() # fetch the Krita layer we like to export krtlayer = Krita.image().activePaintLayer() # create the PIL image pilimage = Image.new("RGB", (krtlayer.width(), krtlayer.height())) # finally do the export it = krtlayer.createRectIterator( 0, 0, krtlayer.width(), krtlayer.height()) finesh = it.isDone() while (not finesh): pilimage.putpixel( (it.x(),it.y()), tuple(it.pixel())) finesh = it.next() # and save the result pilimage.save("/home/user/myimage.jpg")
The following three sample scripts are doing the exactly the same thing, that is invert the pixel of an image, and are written code-wise the same way while different scripting backends are used. It does provide us a way to compare the languages and to show, that the same rich API is accessible to all of them :)