0

I want to run the following command on Windows command prompt:

convert -density 50 -pointsize 70 -font Arial label:"Text with spaces" output.gif

This command uses imagemagick and makes a gif file with the text "Text with spaces" and saves it to output.gif

This works nicely straight from Windows 7 command prompt. Now, I want to run this command from a Java application of mine. Consider:

private void runConvert()
{
    try
    {
        ProcessBuilder pb = new ProcessBuilder("convert","-density","50","-pointsize","70"
        ,"font","Arial","label:","\"Text with spaces\"","output.gif");

        pb.redirectErrorStream(true);
        Process process = pb.start();
        BufferedReader inStreamReader = new BufferedReader(newInputStreamReader(process.getInputStream()));

        while(inStreamReader.readLine() != null){
            System.out.println(inStreamer.readLine());
        }

     } catch (Exception e){
         e.printStackTrace();
     }
}

Problem is, this makes convert echo:

convert.exe: no decode delegate for this image format `' @ error/constitue.c/ReadImage/501

If I try to use runConvert function with a text parameter that has no spaces, like "BurgerKing" it works like a charm. How can I fix it for multi spaces parameters?

user1555863
  • 2,567
  • 6
  • 35
  • 50

1 Answers1

0

You should specify label: and "Text with spaces" as a single argument:

ProcessBuilder pb = new ProcessBuilder("convert","-density","50","-pointsize",
"70","-font","Arial","label:\"Text with spaces\"","output.gif");
dlemstra
  • 7,813
  • 2
  • 27
  • 43