Export a png from kra, a krita document - linux

I am developing a all in one image converter tool using bash commands. So I want to know how to export a krita, ".kra" document with many layers, to a "png" image using command line ?

There is a command line converter for Krita. However from version 2.9 it was removed in favor of calling krita binary with arguments.
If krita version is 2.8 or less you should use calligraconverter
calligraconverter --batch -- input output
In 2.9 you would call krita like this
krita input --export --export-filename output
By default both commands output format is based on the output extension name. For more information run calligraconverter (2.8) OR krita(2.9) commands "--help".

Not a ready command-line utility solution as you wanted but still.
Found following python script from David Revoy's blog
Try to adapt it to your needs.
import sys, zipfile
import Image
import StringIO
if len(sys.argv) != 4:
sys.exit('Usage: '+sys.argv[0]+' <Input> <Output> <Size>')
thumbnail = zipfile.ZipFile(sys.argv[1]).read('preview.png')
im = Image.open(StringIO.StringIO(thumbnail))
im.thumbnail( (int(sys.argv[3]), int(sys.argv[3])) )
im.save(sys.argv[2],'png')

Related

pstoedit gives different result while converting eps to dxf using "dxf" and "dxf_14"

I am using pstoedit as a part of a shell script to convert svg to dxf.
When I use pstoedit -psarg '-dNOSAFER' -dt -f 'dxf: -mm' "${epsfile}" "${dxffile}" in script, the result is like the picture below.
But when i use pstoedit -psarg '-dNOSAFER' -dt -f 'dxf_14: -mm' "${epsfile}" "${dxffile}" the result is like the picture below.
See the difference? dxf gives complete lines, but dxf_14 gives small lines not connected. I read pstohedit -help and it mentions to use dxf_14 because it's newer, but I can't if it's going to produce results like this.
I also see a bunch of options specific to dxf_14, but I'm not sure what to use. Can anyone guide me on what switches to use for dxf_14 to get desired result, like the first picture above?
PS. I'm using Inkscape to create svg and then the script converts svg to eps using inkscape cli and the pstoedit is used to convert eps to dxf, if it helps.
PS2. pstoedit version is pstoedit: version 3.74 / DLL interface 108 (built: Oct 31 2019 - release build - g++ 9.2.0 - 64-bit)

Run Python scour SVG optimizer from script in stead of the CLI

scour for Python does a great job to reduce the size of the SVG maps that I have generated using matplotlib.
However, the documentation only describes how to run it for a single file from the CLI, standard:
scour -i input.svg -o output.svg
What is the best way to run it (in batch mode) from a Python script / from my Jupyter notebook?
I succeeded to 'create' the working code below and optimized 500 SVGs to my satisfaction. But I just copied that code in bits from the testscour.py and I lack the understanding about it...
from scour.scour import makeWellFormed, parse_args, scourString, scourXmlFile, start, run
maps= os.listdir('C:\\Hugo\\Sites\\maps\\')
for m in maps[:]:
if afbeelding[-4:]=='.svg':
inputfile = open('C:\\Hugo\\Sites\\maps\\' + m, 'rb')
outputfile = open('C:\\Hugo\\Sites\\allecijfers\\static\\images\\maps\\' + m, 'wb')
start(options, inputfile, outputfile)
Related questions (trying to learn): What is the best way to decompose a module like scour in order to find the right callable functions? (I would not have found the function start in scour.py ) Or could I have called the CLI command from the Python script above in order to execute it in batch mode?
I like your question because it pointed me to testscour.py, thanks a lot.
That said, the code imports scour first,
then makes makes a list from your map folder;
then goes through the list one by one, if it is an svg, it uses the "start" method to call scour.
so the working piece is
start(options, inputfile, outputfile)
Note that it needs an opened file handler, usually you make that with "with".
Have fun
To use Scour programmatically first install it using PIP.
pip install scour
Then add this to your code (using whatever names you like).
from scour.scour import start as scour, parse_args as scour_args, getInOut as scour_io
def scour_svg(infilename,outfilename):
options = scour_args()
options.infilename = infilename
options.outfilename = outfilename
// Set options here or accept defaults.
(input, output) = scour_io(options)
scour(options, input, output)
if __name__ == '__main__':
infilename = 'C:\\Users\\...\\svg_in.svg'
outfilename = 'C:\\Users\\...\\svg_scoured.svg'
scour_svg(infilename,outfilename)
print('The END')
Use the scour_svg function to read in an SVG file, scour it, then write it out to a file.
Options can be adjusted in the code in the same way the infilename and outfilename are provided above. Refer to: -
https://github.com/scour-project/scour/wiki/Documentation
or just do >scour --help in the command prompt.

what is the proper syntax of gmic apply_video

I am trying to apply a gmic filters using apply_video option of gmic utility for linux .
./gmic --apply_video 'small.mp4','-denoise 30,10' -o convert.avi
but the output is an error in terminal
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Apply command 'small.mp4,-denoise 30,10' on video stream '', with output filename '', first frame 0, last frame -1 and frame step 1.
[gmic] *** Error in ./apply_video/*local/*substitute/ *** Command '-basename': Undefined argument '$1', in expression '$1' (for 2 arguments specified).
[gmic] Command '-basename' has the following description:
-basename:
file_path,_variable_name_for_folder
Return the basename of a file path, and opt. its folder location.
When specified 'variable_name_for_folder' must starts by an underscore
(global variable accessible from calling function).
so what is the correct syntax for gmic --apply_video ?
I am using version 1.7.3
I'm using latest available version 1.7.5_pre, and I use it like this :
$ gmic -w -apply_video input.avi,\"-denoise 30,10\",0,-1,1,output.avi
For G'MIC options, you can use the excellent offline help
gmic -h
or
gmic -h -apply_video
Which as of version 1.7.8 gives
gmic: GREYC's Magic for Image Computing.
Version 1.7.8, Copyright (c) 2008-2016, David Tschumperle.
(http://gmic.eu)
-apply_video:
video_filename,_"command",_first_frame>=0,_last_frame={ >=0 | -1=last },
_frame_step>=1,_output_filename
Apply a G'MIC command on all frames of the specified input video file, in a streamed way.
If a display window is opened, rendered frames are displayed in it during processing.
The output filename may have extension '.avi' (saved as a video), or any other usual image file
extension (saved as a sequence of images).
Default values: 'first_frame=0', 'last_frame=-1', 'frame_step=1' and
'output_filename=(undefined)'.

UnicodeEncodeError: 'charmap' codec can't encode... solution in traceback? [duplicate]

Ok, i want to print a string in my windows xp console.
There are several characters the console cant print, so i have to encode to my stdout.encoding which is 'cp437'. but printing the encoded string, the 'ß' is printed as '\xe1'. after decoding back to unicode and printing the string, i get the output i want. but this feels somewhat wrong. how is the correct way to print a string and get ? for non-printable characters?
>>>var
'Bla \u2013 großes'
>>>print(var)
UnicodeEncodeError: 'charmap' codec can't encode character '\u2013'
>>>var.encode('cp437', 'replace')
b'Bla ? gro\xe1es'
>>>print(var.encode('cp437', 'replace'))
b'Bla ? gro\xe1es'
>>>var.encode('cp437', 'replace').decode('cp437')
'Bla ? großes'
>>>print(var.encode('cp437', 'replace').decode('cp437'))
Bla ? großes
edit:
#Mark Ransom: since i print a lot this makes the code pretty bloated i feel :/
#eryksun: excactly what i was looking for. thanks a lot!
To print Unicode characters that can't be represented using the console codepage, you could use win-unicode-console Python package that uses Unicode API such as ReadConsoleW/WriteConsoleW() to read/write Unicode from/to Windows console directly:
#!/usr/bin/env python3
import win_unicode_console
win_unicode_console.enable()
try:
print('Bla \u2013 großes')
finally:
win_unicode_console.disable()
save it to test_unicode.py file, and run it:
C:\> py test_unicode.py
You should see:
Bla – großes
As a preferred alternative, you could use run module (included in the package), to run an ordinary script with enabled Unicode support in Windows console:
C:\> py -m run unmodified_script_that_prints_unicode.py
To install win_unicode_console module, run:
C:\> pip install win-unicode-console
Make sure to select a font able to display Unicode characters in Windows console.
To save the output of a Python script to a file, you could use PYTHONIOENCODING envvar:
C:\> set PYTHONIOENCODING=utf-8:backslashreplace
C:\> py unmodified_script_that_prints_unicode.py >output_utf8.txt
Do not hardcode the character encoding of your environment inside your script, print Unicode instead. The examples show that the same script may be used to print to the console and to a file using different encodings and different methods.
An alternate solution is to not use the crippled Windows console for general unicode output. Tk text widgets (accessed as tkinter Text instances) handle all BMP chars as long as the selected font will.
Since Idle used tkinter, it can as well. Running an Idle editor file (call it tem.py) containing
print('Bla \u2013 großes')
prints the following in the Shell window.
Bla – großes
A file can be run through Idle from the console with -m and -r.
C:\>python -m idlelib -r c:/programs/python34/tem.py
This opens a shell window and prints the same as above. Or you can create your own tk window with Label or Text widget.

How to convert Balsamiq mockups to text strings txt with Python34 script on Windows XP

I've been trying to run these scripts https://github.com/balsamiq/mockups-strings-extractor within XP. I'm getting errors per this screenshot https://www.dropbox.com/s/rlbqp1iytkwvq3m/Screenshot%202014-05-30%2011.57.48.png
Also I tried CD into my test directory and although a text output file is generated it is empty and I still get these errors https://www.dropbox.com/s/odjfbr97e5i4gnn/Screenshot%202014-05-30%2012.09.31.png
Is anybody running Balsamiq on windows able to make this work ?
1) From the looks of the first error pic you included, you were trying to execute a Windows Shell command inside of a Python Interpreter. If you've still got the window open, type quit() before attempting your command again.
2) Your script was written for Python 2.x. If you're using Python 3.x, you'll need to add parentheses to the print lines in the script file and change urllib to urllib.parse. I made the changes below:
import os
import glob
import re
import urllib.parse
for infile in glob.glob( os.path.join(".", '*.bmml') ):
print("STRINGS FOUND IN " + infile)
print("===========================================================")
f = open (infile,"r")
data = f.read()
p = re.compile("<text>(.*?)</text>")
textStrings = p.findall(data)
print(urllib.parse.unquote('\n'.join(textStrings))+"\n")
f.close()
Hope this helps.

Resources