Piping SVG file into ImageMagick
-
26-06-2021 - |
문제
Sorry if this belongs on serverfault
I'm wondering what the proper way is to use an SVG(xml) string as standard input
for a "convert msvg:- jpeg:- 2>&1"
command (using linux)
Currently I'm just saving a temp file to use as input, but the data originates from an API in my case, so feeding the string directly to the command would obviously be most efficient.
I appreciate everyone's help. Thanks!
해결책
This should work:
convert - output.jpg
Example:
convert logo: logo.svg
cat logo.svg | convert - logo.jpg
Explanation:
The example's first line creates an SVN file and writes it to disk. This is only a preparatory stop so that we can run the second line.
The second line is a pipeline of two commands:
cat
streams the bytes of the file to stdout (standard output).The first line served only as preparation for the next command in the pipeline, so that this next command has something to read in.
This next command is
convert
.The
-
character is a way to tellconvert
to read its input data not from disk, but from stdin (standard input).So
convert
reads its input data from its stdin and writes its JPEG output to the filelogo.jpg
.So my first command/line is similar to your step described as 'currently I'm just saving a temp file to use as input'.
My second command/line does not use your API (I don't have access to it, do I?), but it demonstrates a different method to 'feeding a string directly to the command'.
So the most important lesson is this: Whereever
convert
would usually read input from a file and where you would write the file's name on the commandline, you can replace the filename by-
to tellconvert
it should read from stdin. (But you need to make sure that there is actually something offered onconvert
's standard input which it can digest...)
Sorry, I can't explain better than this...