I'm trying to get following ImageMagick command working with the Java ProcessBuilder:
convert.exe image.png `( `+clone -alpha extract mask.png -compose Darken -composite `) -compose CopyOpacity -composite out.png
The file paths (source image, mask image and destination image) are configurable. If I enter the command in PowerShell or Windwos Cmd it is working as expected. When I'm trying to execute the same command via Java ProcessBuilder, it fails.
Here is my last code:
File srcFile = new File("C:/Users/AAA/Desktop/PNG/image.png");
File maskFile = new File("C:/Users/AAA/Desktop/PNG/mask.png");
File destFile = new File("C:/Users/AAA/Desktop/PNG/out-1.png");
List<String> commands = new ArrayList<>();
commands.add("C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe");
commands.add(srcFile.getAbsolutePath());
commands.add(" `( `+clone -alpha extract " + maskFile.getAbsolutePath() + " -compose Darken -composite `)");
commands.add("-compose CopyOpacity -composite " + destFile.getAbsolutePath());
ProcessBuilder pb = new ProcessBuilder(commands);
pb.inheritIO();
try {
int i = pb.start().waitFor();
System.out.println("Finished with code: " + i);
} catch (Exception e) {
System.out.println("asdasdasd: " + e);
}
And this is the ourput from the process builder:
convert.exe: unable to open image `/Users/AAA/Desktop/PNG/mask.png -compose Darken -composite )': No such file or directory @ error/blob.c/OpenBlob/2692.
convert.exe: no decode delegate for this image format ` ( +CLONE -ALPHA EXTRACT C' @ error/constitute.c/ReadImage/501.
convert.exe: missing an image filename `-compose CopyOpacity -composite C:\Users\AAA\Desktop\PNG\out-1.png' @ error/convert.c/ConvertImageCommand/3214.
It seems that the commands aren't interpreted in the right way
I have tried following possibilities, but most of them with the same outcome.
- Escape paths
- Remove PowerShell escape character
``
- Split the command in single array items (e.g. "(", "+clone", "-alpha")
What do I miss?