annotate() - text with \n overlaps itself

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
whatdoido
Posts: 27
Joined: 2011-01-22T16:54:46-07:00
Authentication code: 8675308

annotate() - text with \n overlaps itself

Post 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;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

We compiled your source against ImageMagick 7.0.8-16, the latest release, and it worked as expected-- no overlapping text.
whatdoido
Posts: 27
Joined: 2011-01-22T16:54:46-07:00
Authentication code: 8675308

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

Post 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?
Post Reply