0

I'm trying to use im4java to generate sample image with text on image with the pattern. My code:

    ConvertCmd convertCmd = new ConvertCmd();

    IMOperation imOperation = new IMOperation();
    imOperation.size(564, 564);
    imOperation.tile(patternImg);
    imOperation.background("none");
    imOperation.stroke("black");
    imOperation.strokewidth(2);
    imOperation.fill("white");
    imOperation.gravity("center");
    imOperation.pointsize(40);
    imOperation.border(3, 3);
    imOperation.label(generateImageRequestDTO.getMainText());
    imOperation.composite();
    imOperation.addImage(absolutePathWorkDir + "/" + "test.jpg");
    convertCmd.run(imOperation);

Which generate such script:

convert \
   -size "564x564" -tile "/var/images/patterns/1.jpg" \
  -background "none"-stroke "black" -strokewidth "2" -fill "white" \
  -gravity "center"-pointsize "40" -border "3x3" -label "This is some text" \
  -composite "/var/images/workdir/test.jpg"

Which is almost what I need. This is the code which I'm trying to generate:

convert \
   -size "564x564" tile:"/var/images/patterns/1.jpg" \
  -background "none"-stroke "black" -strokewidth "2" -fill "white" \
  -gravity "center"-pointsize "40" -border "3x3" label:"This is some text" \
  -composite "/var/images/workdir/test.jpg"

Basiclly

  • -tile ==> tile:
  • -label ==> label:

what i'm missing here?

fmw42
  • 46,825
  • 10
  • 62
  • 80
kingkong
  • 1,537
  • 6
  • 27
  • 48
  • -label is not the same as label:. The first puts text into the label meta data field. The second create an image from the text. -tile and tile: do similar things, but follow different syntax. See https://imagemagick.org/Usage/canvas/#tile. Sorry, I do not know im4java. – fmw42 Oct 21 '19 at 22:07
  • Sorry, I do not know im4java. But there may be no direct equivalent of label: in im4java. You may have to use the equivalent of either -annotate or -draw for creating a text image. – fmw42 Oct 22 '19 at 03:34
  • See http://im4java.sourceforge.net/api/org/im4java/core/IMOps.html#annotate() and http://im4java.sourceforge.net/api/org/im4java/core/IMOps.html#draw(java.lang.String) and https://imagemagick.org/Usage/text/ for Imagemagick documentation for -annotate and -draw for text to image conversion. – fmw42 Oct 22 '19 at 03:43
  • @fmw42 - so while I'm performing to commands that I posted, I'm getting 2 different outputs."label:" is working different that annotate - I can automatically scale text to fit the image. Same with -tile and tile: output is totally different. – kingkong Oct 22 '19 at 06:23
  • 2
    Try adding the `tile:` & `label:` prefix to `imOperation.addImage` method. Like `imOperation.addImage("tile:"+patternImg);` – emcconville Oct 22 '19 at 14:18

1 Answers1

0

Thank You a lot @emcconville ! That works!

Try adding the tile: & label: prefix to imOperation.addImage method. Like imOperation.addImage("tile:"+patternImg); – emcconville

kingkong
  • 1,537
  • 6
  • 27
  • 48