0

I am having a tough time figuring out the sequence of events to have a caption of one dimension. Then have this caption on an image of a larger dimension.

Right now my sequence of operations are:

            IMOperation op = new IMOperation();

                op.background("bgColor");
                op.fill("fgColor");
                op.pointsize(44);
                op.gravity(" Center");
                op.font("AppleChancery"); // font
                op.size(800, 800);

                op.addRawArgs("caption: "+text);

                op.resize(1080,1080);

                op.addImage("src/test/resources/images/test.jpeg");

                cmd.run(op);

This always creates the image at 1080x1080 with the caption using that to calculate the margins.

I've tried running an addImage before the caption call to save the image at one dimension, but I either get a 800x800 image or I get 2 images one 800x800 and one blank.

How should I sequence these operations?

Thanks.

Kunal
  • 398
  • 2
  • 4
  • 18
  • So you want the caption to be added to the 800x800 image and then resize the image and the caption? If so you could try to pipe the operations (IIRC using `addImage("-")` should do the trick) and resize to 1080x1080 in a second step. – Thomas Oct 26 '18 at 13:25
  • More that I would like the caption to stay at 800x800 framed within the center of the newly created image of 1080x1080. The resize looks to me to affect the caption as well. – Kunal Oct 26 '18 at 13:39
  • Ah I see, in that case you could try to render the caption to an otherwise empty image with size 800x800 and transparency and then paint that image onto the resized base image. I don't remember the acutal setup atm but you should be able to find something on that in the docs. – Thomas Oct 26 '18 at 13:42
  • Let me try this, thanks for the approach. – Kunal Oct 26 '18 at 13:52
  • 1
    In ImageMagick, you can create your 800x800 caption image, then just extend it to the 1000x1000 size using gravity to position it as desired assuming the background is a constant color via -background. See https://imagemagick.org/Usage/crop/#extent – fmw42 Oct 26 '18 at 16:26
  • Hi thank you both for the input. I decided to start with fmw42's approach since it was easier to implement. It works. Used gravity + extent and resized to the larger size. Caption remained same dimensions. – Kunal Oct 26 '18 at 20:30

0 Answers0