How to composite array of images
jansnapple opened this issue · comments
I'm trying to use composite on a bunch of images with different x and y coordinates but it says
Read loop ended: composite: must be 1 x coordinates
but the documentation says that it can take an array of coordinates:
Optional parameters
x – Array of x coordinates to join at, std::vector.
y – Array of y coordinates to join at, std::vector.
This is the code, it's supposed to do it once at (0,0) and once at (500,500):
std::vector<VImage> images = {v, v};
std::vector<int> modes = {VIPS_BLEND_MODE_ATOP, VIPS_BLEND_MODE_ATOP};
std::vector<int> x = {0, 500};
std::vector<int> y = {0, 500};
in = in.composite(images, modes, VImage::option()
->set("x", x)
->set("y", y)
);
in.write_to_file("out.png");
It works fine when I just do one image:
in = in.composite(v, VIPS_BLEND_MODE_ATOP, VImage::option()
->set("x", 0)
->set("y", 0)
);
But not multiple
Am I doing something wrong?
Hi @jansnapple,
It should work, I'd think. Would you mind making a complete test program I can run? Otherwise I'll have to make one before I can try anything :(
Ah I think I see -- the first image in images
is the base, or background image, so it's always at (0, 0). For n
input images, you need to supply n - 1
modes, coordinates, etc. etc.
The docs are not very clear on this:
https://www.libvips.org/API/current/libvips-conversion.html#vips-composite
I'll try to improve them.
Hi, it works now, thank you! I guess I was looking at the wrong docs, I was looking at https://www.libvips.org/API/current/cpp/classVImage.html#afd79a8056df8af9f7e15a38adc244995 instead of that one but that one explains it a lot better. Thanks!
The C++ docs are automatically generated by doxy and lack the detail of the main API docs :( There doesn't seem to be an easy way to combine them, unfortunately.
Maybe it's possible to do something clever with docbook and some xml rewrites?