Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

linux - How to use stdin with caption in ImageMagick

My understanding from reading the ImageMagick documentation regarding text, is that the @- notation reads the contents of standard input.

As such, this should be a fairly straight forward way to render Hello World.

printf "Hello
World" | 
convert 
  -size 1280x100 
  -background '#0000FF10' 
  -density 90 
  -gravity Center 
  -fill black 
  -font Helvetica 
  caption:@- 
  test.png

On OS X 10.11.5 via HomeBrew, this works, using convert Version: ImageMagick 6.9.4-3 Q16 x86_64 2016-05-20.

enter image description here

However on Ubuntu 16.04 LTS, the identical command does not work, using convert Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-06-01. In fact, it renders the stdin operator, literally.

enter image description here

The only thing I was able to find that remotely looked like this problem on Google was this article, dated back in Oct 2015 in which ImageMagick 6.9.2-5 Beta was patched to fix a similar problem.

QUESTION: Am I not escaping it properly, is there really a problem in ImageMagick, or is my Linux Distro picking up a historical version of ImageMagick with the bug and I need to build from source?


Much Later After Many Experiments

SOLVED ...? Built ImageMagick 7.0.2 from source on the Ubuntu box and the above command worked as desired. Was there a better solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No need to build from source. Just replace @- with "`tee`" :

printf "Hello
World" | 
convert 
  -size 1280x100 
  -background '#0000FF10' 
  -density 90 
  -gravity Center 
  -fill black 
  -font Helvetica 
  caption:"`tee`" 
  test.png

`tee` will execute first and 'process' stdin before completing the convert command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...