0

I used the terminal command to convert all the images in the folder into RGB images using imagemagick tool

"C:\Documents and Settings\admin\My Documents\NetBeansProjects\Archiveindexer\resources\T0003SathyabamaT\Active\CBE_2014_03_02_FE_04_MN_IMAGES_CONVERTED" is my image folder

terminal command:

 myimagefolder> mogrify -colorspace RGB *.jpg

This works fine. But when run this using java it is not working

File destpathfinalconv = new File("C:/Documents and Settings/admin/My          Documents/NetBeansProjects/Archiveindexer/T0003SathyabamaT/Active/CBE_2014_03_02_FE_04_MN_IMAGES_CONVERTED");
         ProcessBuilder pb = new ProcessBuilder("mogrify", "-colorspace RGB", destpathfinalconv.toString(),
                     "*.jpg");

      pb.redirectErrorStream(true);

      Process p = pb.start();
      BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line = null;
      while ((line = br.readLine()) != null) {
          System.err.println(line);
      }
      System.err.println("Error "+p.waitFor());

System is throwing error "mogrify.exe: unrecognized option `-colorspace RGB' @ error/mogrify.c/MogrifyImageCommand/4254. Error 1"

Any idea please suggest.

2 Answers 2

2

You are specifying '-colorspace RGB' as a single argument, but it should be two arguments. And you should combine the path and file and search pattern into a single argument. The constructor of ProcesBuilder should be called like this:

ProcessBuilder pb = new ProcessBuilder("mogrify", "-colorspace", "RGB",
  destpathfinalconv.toString() + "\\" + "*.jpg");
Sign up to request clarification or add additional context in comments.

1 Comment

mogrify.exe: unable to open image `C:\Documents and Settings\admin\My Documents\NetBeansProjects\Archiveindexer\T0003SathyabamaT\Active\CBE_2014_03_02_FE_04_MN_IMAGES_CONVERTED*.jpg': No such file or directory @ error/blob.c/OpenBlob/2643. Error 1. This also shows error
0

Try this:

   ProcessBuilder pb = new ProcessBuilder(
       "mogrify", 
       "-colorspace",
       "RGB", 
       destpathfinalconv.toString(),
       "*.jpg");

Explanation: Each String argument in the ProcessBuilder ends up as a "word" (according to shell parlance) or a separate parameter in the resulting execve call.

Combining "-colorspace RGB" results in a single parameter to mogrify, which is the (unknown) option "-colorspace\ RGB".

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.