문제

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:

  1. 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.

  2. The second line is a pipeline of two commands: cat streams the bytes of the file to stdout (standard output).

  3. The first line served only as preparation for the next command in the pipeline, so that this next command has something to read in.

  4. This next command is convert.

  5. The - character is a way to tell convert to read its input data not from disk, but from stdin (standard input).

  6. So convert reads its input data from its stdin and writes its JPEG output to the file logo.jpg.

  7. So my first command/line is similar to your step described as 'currently I'm just saving a temp file to use as input'.

  8. 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'.

  9. 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 tell convert it should read from stdin. (But you need to make sure that there is actually something offered on convert's standard input which it can digest...)

Sorry, I can't explain better than this...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top