[SOLVED] pipe command output to convert ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
deej

[SOLVED] pipe command output to convert ?

Post by deej »

Is there, I am wondering, a way of piping the output of a command -
the 'fortune' command for example - to 'convert' in order to save the
output in png format ? I am currently piping to 'enscript' and then
passing the resultant image to 'convert'. I'd like to get rid of the
'enscript' step, if possible.

Here is an example of what I'm doing at the moment:

Code: Select all

fortune | enscript -o From_Enscript -B -r -fCourier@16/18 
convert -trim From_Enscript result.png 
Merry Xmas to all...

Deej
Last edited by deej on 2008-12-25T03:19:32-07:00, edited 1 time in total.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: pipe command output to convert ?

Post by el_supremo »

This works with Windows XP and IM 6.4.6 Q8 so it should work with Linux.

Code: Select all

echo Merry Christmas | convert -font Arial -pointsize 72 -fill red -background green text:- -trim cap.png
The piped text is picked up by "text:-" and the rest sets up the font/size/colour and then trims the result.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
deej

Re: pipe command output to convert ?

Post by deej »

Ah, many thanks el_supremo, I shall give it
a go - and report back.

The Seasons Best Wishes to you...

Deej
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: pipe command output to convert ?

Post by el_supremo »

The Seasons Best Wishes to you...
and to you too :-)

@magick/Anthony
Although text:- reads the standard input, I can't get caption:- or label:- to do the same thing. Are they supposed to work or is this function limited to text:-?


Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pipe command output to convert ?

Post by fmw42 »

el_supremo wrote:
The Seasons Best Wishes to you...
and to you too :-)

@magick/Anthony
Although text:- reads the standard input, I can't get caption:- or label:- to do the same thing. Are they supposed to work or is this function limited to text:-?


Pete

Pete,

These work for me (IM 6.4.8-1 Q16):

echo "Merry Christmas" | convert -font Arial -pointsize 72 -fill red -background green \
text:- -trim tmp1.png

But you need @- for label: and caption:

echo "Merry Christmas" | convert -font Arial -pointsize 72 -fill red -background green \
label:@- -trim tmp2.png


echo "Merry Christmas" | convert -font Arial -pointsize 72 -fill red -background green \
-size 320x caption:@- -trim tmp3.png

Seems a bit inconsistent. But there must be some reason. Also, text:@- does not work.

Fred
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: pipe command output to convert ?

Post by el_supremo »

On Windows those caption and label commands don't work. IM 6.4.6 Q8
label:@- causes this error:

Code: Select all

convert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
imconvert: missing an image filename `cap.png' @ convert.c/ConvertImageCommand/2710.
whereas caption:@- causes this:

Code: Select all

convert: geometry does not contain image `@-' @ statistic.c/GetImageBoundingBox/217.
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
I don't understand the complaint about geometry. I can make the -size much larger than it needs and it still complains

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pipe command output to convert ?

Post by fmw42 »

el_supremo wrote:On Windows those caption and label commands don't work. IM 6.4.6 Q8
label:@- causes this error:

Code: Select all

convert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
imconvert: missing an image filename `cap.png' @ convert.c/ConvertImageCommand/2710.
whereas caption:@- causes this:

Code: Select all

convert: geometry does not contain image `@-' @ statistic.c/GetImageBoundingBox/217.
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
I don't understand the complaint about geometry. I can make the -size much larger than it needs and it still complains

Pete
Guess we need to hear from Magick or Anthony. Those work for me on Mac OSX Tiger (unix). So must be some special issue with @ on windows. Did you try escaping it, I assume ^@-

Fred
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: pipe command output to convert ?

Post by el_supremo »

I tried all sorts of escapes and quoting and nothing works.

Pete.
Merry Christmas Fred and All
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pipe command output to convert ?

Post by fmw42 »

el_supremo wrote:I tried all sorts of escapes and quoting and nothing works.

Pete.
Merry Christmas Fred and All

Happy Holidays to you too, Pete.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: pipe command output to convert ?

Post by anthony »

The '-' is a special filename meaning either read from standard input (piped input ot keyboard) or write to standard output (pipe to another command or to the screen).

text: reads from a file name so you use text:-

label: and caption: read a string. so you prepend '@' to have the string read from a filename EG: label:@-
el_supremo wrote:whereas caption:@- causes this:

Code: Select all

convert: geometry does not contain image `@-' @ statistic.c/GetImageBoundingBox/217.
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
I don't understand the complaint about geometry. I can make the -size much larger than it needs and it still complains
If you read IM Examples on text to image handling caption, the first thing is says is that caption: requires a -size setting to specify a image 'width' for the caption for word wrapping purposes. If you don't have it you get a geometry error as you saw.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
deej

Re: pipe command output to convert ?

Post by deej »

Thank you to everyone who replied, this is what finally worked for me [ on Linux ]:

Code: Select all

convert -font courier -pointsize 18 label:@- -trim signature1.png
( thx fmw32 :D )

Deej
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] pipe command output to convert ?

Post by anthony »

After the -trim add a +repage before saving the image, so as to avoid problems with 'virtual canvas offsets' that is left for expert users.

See IM Usage Examples, Trim
http://www.imagemagick.org/Usage/crop/#trim
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
deej

Re: [SOLVED] pipe command output to convert ?

Post by deej »

After the -trim add a +repage before saving the image, so as to avoid problems with 'virtual canvas offsets' that is left for expert users.
OK, done. All working fine now, thanks again everyone :D

Deej
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: [SOLVED] pipe command output to convert ?

Post by el_supremo »

the first thing is says is that caption: requires a -size setting
Yes I know, that's why I said "I can make the -size much larger than it needs and it still complains "

These all fail no matter how I escape them:

Code: Select all

>echo Merry Christmas | imconvert -font Arial -pointsize 72 -fill red -background green label:@- -trim cap_l.png
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
imconvert: missing an image filename `cap_l.png' @ convert.c/ConvertImageCommand/2710

>echo Merry Christmas | imconvert -font Arial -pointsize 72 -fill red -background green label:^@- -trim cap_l.png
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
imconvert: missing an image filename `cap_l.png' @ convert.c/ConvertImageCommand/2710.

>echo Merry Christmas | imconvert -font Arial -pointsize 72 -fill red -background green "label:@-" -trim cap_l.png
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
imconvert: missing an image filename `cap_l.png' @ convert.c/ConvertImageCommand/2710.

>echo Merry Christmas | imconvert -font Arial -pointsize 72 -fill red -background green -size 1000x500 caption:@- -trim c
ap_c.png
imconvert: geometry does not contain image `@-' @ statistic.c/GetImageBoundingBox/217.
imconvert: unable to read blob `-': No such file or directory @ blob.c/FileToBlob/868.
This is with ImageMagick 6.4.6 2008-12-01 Q8

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] pipe command output to convert ?

Post by anthony »

el_supremo wrote:
the first thing is says is that caption: requires a -size setting
Yes I know, that's why I said "I can make the -size much larger than it needs and it still complains "[/code]
Works for me under linux. Could pipelines be a problem under windows?

I have had no indication that '@' needs any form of escaping under windows. But no reports of success for it either. Of course I am not a windows user so can only go by what I have been told.
And what I have been told has been noted in IM examples,
http://www.imagemagick.org/Usage/api/#windows
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply