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?

3
  • I recommend to use im4java It is reliable interface library to execute ImageMagick operations.
    – user784540
    Jul 16, 2014 at 8:43
  • You are missing a '-' in front of your "font" argument. It explains your error if that is not a typo.
    – dlemstra
    Jul 16, 2014 at 9:03
  • @dlemstra that's a typo here Jul 16, 2014 at 10:36

1 Answer 1

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");
4
  • Have you tried this? convert echos nothing but there's no file output. Jul 16, 2014 at 11:18
  • Did you check the working directory of your application for the file output.gif? Your file might be written to a different location on your disk then what you are expecting.
    – dlemstra
    Jul 16, 2014 at 12:22
  • Checked. Also changed it into a known directory by changing output.gif to c:\\testings\\output.gif. Jul 16, 2014 at 12:37
  • Did you also check the output from process.getErrorStream?
    – dlemstra
    Jul 16, 2014 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.