Re: [Gimp-user] Gimp Java Batch not working



On 03/07/2014 10:54 AM, Andreas Truszkowski wrote:
... the Java code :) :

File imageFile = new File(this.targetDir.getPath() + File.separator + UUID.randomUUID().toString() + ".png"); File testFile = new File(this.targetDir.getPath() + File.separator + "test.png");
        Tools.compressJpegFile(imageFile, inImage, 1.0f);
String argString = String.format("(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE \"%s\" \"%s\")))"
                + "(drawable (car (gimp-image-get-active-layer image))))"
+ "(plug-in-sobel RUN-NONINTERACTIVE image drawable 1 1 1)" + "(gimp-file-save RUN-NONINTERACTIVE image drawable \"%s\" \"%s\")" + "(gimp-image-delete image))", imageFile.getPath(), imageFile.getPath(), testFile.getPath(), testFile.getPath()); String script = String.format("\"C:\\Program Files\\GIMP 2\\bin\\gimp-2.8.exe\" -i -b '%s' -b '(gimp-quit 0)'", argString);
        ProcessBuilder builder = new ProcessBuilder(script);
        builder.directory(this.targetDir);
        builder.redirectErrorStream(true);
        if (!this.isCancelled()) {
            Process process = builder.start();
            InputStream is = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            System.out.println("Program terminated!");
            process.waitFor();
        }

Kind regards,
Andreas

Am 07.03.2014 10:52, schrieb Andreas Truszkowski:
Hi there,

I am new to Gimp and first I want to thank the Gimp community for such a great application.

But here is my problem. I try to process images from within a Java application. When I run the assembled batch command the gimp console writes that the execution was successfull.


But actually nothing happens. Here is my Java code:


The resulting command line is:

"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" -i -b '(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "z:\test\26cf5abe-eaa1-4ddd-af04-3d9e59804ed2.png" "z:\test\26cf5abe-eaa1-4ddd-af04-3d9e59804ed2.png")))(drawable (car (gimp-image-get-active-layer image))))(plug-in-sobel RUN-NONINTERACTIVE image drawable 1 1 1)(gimp-file-save RUN-NONINTERACTIVE image drawable "z:\test\test.png" "z:\test\test.png")(gimp-image-delete image))' -b '(gimp-quit 0)'

Executing this directly from command line does not fix the problem. Anyone a clue what I make wrong? Thank you in advance...


You should really use the |*ProcessBuilder <http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#ProcessBuilder%28java.util.List%29>*(List <http://docs.oracle.com/javase/7/docs/api/java/util/List.html><String <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html>> command) contructor, that will give you more control on the parameters and let you avoid a lot of quoting and escaping. And instead of calling Gimp, make it call a small script/program that dumps its parameters to stdout. As far as I can tell you are using the Unix shell syntax (leading single quote) while the file names indicate you are on Windows...

You will also save you a lot of grief by making all your scheme code a small script. Once that works you can try to pack the whole script back in a parameter.

If you call gimp with -c you will get messages printed to the console (ie, stdout) instead of being displayed by the graphical UI




|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]