Page 1 of 1

annotate() - text with \n overlaps itself

Posted: 2018-12-12T04:02:58-07:00
by whatdoido
I want to create a text overlay (text set via annotate()) onto an existing image with the sample code below. However, if the text has newline characters the text is overlapping on top of itself. The grey box on the output image should say:

Code: Select all

text
with
newline breaks
The output generated is:
Image

Is there special handling for newline?

Fedora 28, x64, ImageMagick 6.9.9-38 Q16

Code: Select all

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <strings.h>
#include <limits.h>

#include <string>
#include <sstream>
#include <iostream>
#include <cassert>

using namespace  std;

#include <Magick++.h>



int main(int argc, char* const argv[])
{
    int  ret = 0;
    try
    {
        ostringstream  os;
        os << "text\nwith\nnewline breaks";

        Magick::Image  magick(argc == 2 ? argv[1] : "600x400", "blue");

        Magick::Image  info(Magick::Geometry(magick.columns(), magick.rows()), "grey");
        info.borderColor("grey");
        info.fontPointsize(28);
        info.annotate(os.str(), Magick::Geometry("+10+10"), MagickCore::WestGravity);
        info.trim();
        info.border();
        info.opacity(65535/3.0);
        info.transparent("grey");

        cout << "composite size=" << info.columns() << "x" << info.rows() << endl;

        if (info.columns() > magick.columns()-10) {
            ostringstream  os;
            os << magick.columns()-10 << "x";
            info.resize(os.str());
        }


        magick.composite(info,
                            Magick::Geometry(info.columns(), info.rows(), 10, magick.rows()-info.rows()-10),
                            MagickCore::DissolveCompositeOp);

        magick.write("magick-label-composite.jpg");
    }
    catch (const std::exception& ex)
    {
        cerr << "failed to magick - " << ex.what() << endl;
        ret = 1;
    }

    return ret;
}

Re: annotate() - text with \n overlaps itself

Posted: 2018-12-12T04:19:49-07:00
by magick
We compiled your source against ImageMagick 7.0.8-16, the latest release, and it worked as expected-- no overlapping text.

Re: annotate() - text with \n overlaps itself

Posted: 2018-12-12T06:22:55-07:00
by whatdoido
I've just tried installed the github master (3026328a5c87ed95822136405dd1665d627ea201) and recompiled and link but it still produces the same errornous output image. I can see that its linked against the 7.x libs

Code: Select all

$ ldd a.out | grep Magick
	libMagick++-7.Q16HDRI.so.4 => /lib64/libMagick++-7.Q16HDRI.so.4 (0x00007f2ca870d000)
	libMagickWand-7.Q16HDRI.so.6 => /lib64/libMagickWand-7.Q16HDRI.so.6 (0x00007f2ca83de000)
	libMagickCore-7.Q16HDRI.so.6 => /lib64/libMagickCore-7.Q16HDRI.so.6 (0x00007f2ca7cfb000)
Additionally it looks like the opacity() method has been dropped from the latest Image interface (i commented this out to make it compile). Did you do mod to the sample code to make this work?

Re: annotate() - text with \n overlaps itself

Posted: 2019-01-23T23:15:52-07:00
by imma4