I am trying to use im4java to create a jpg file with yellow text centered on a black background.
Using Imagemagick, the following command line works:
convert -size 1400x1050 -stroke yellow -fill yellow -font Courier -pointsize 40 -gravity Center caption:"Sample Text\nLine 2" -fill black -opaque white ~/test.jpg
I tried the following in Java to replicate this:
ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
op.size(1400, 1050)
.stroke("yellow")
.fill("yellow")
.font("Courier")
.pointsize(40)
.gravity("center")
.caption("Sample Text\nLine 2")
.fill("black")
.opaque("white")
.addImage("~/test.jpg");
try {
cmd.run(op);
} catch(Exception e) {
System.out.println(e);
}
but executing this gives:
org.im4java.core.CommandException: org.im4java.core.CommandException: convert-im6.q16: no images defined `~/test.jpg' @ error/convert.c/ConvertImageCommand/3234.
If I change the command to:
op.version()
I get the same output as:
convert -version
All examples I have found online start with an existing image file, modify it, and then store the result, so I can't find help there.
I am on Linux Mint 22.2 with Imagemagick version 6.9.12 and im4java version 1.4.0.
What is incorrect in the im4java operation I am trying to do? Any help is appreciated.