-
Hi, it's me again :P. I'm attempting to load an animated GIF, resize all of its frames via I have the following code: VipsImage* image = vips_image_new_from_buffer(input_image, input_length, "", "n", -1, NULL);
int page_width = vips_image_get_width(image);
int page_height = vips_image_get_page_height(image);
int n_pages = vips_image_get_n_pages(image);
VipsImage* pages[n_pages];
for(int i = 0; i < n_pages; i++) {
vips_crop(image, &pages[i], 0, i * page_height, page_width, page_height, NULL);
vips_resize(pages[i], &pages[i], scale, NULL), EXEC_OPERATION_VIPS_ERR);
}
VipsImage* out;
vips_arrayjoin(pages, &out, n_pages, "across", 1, NULL);
vips_gifsave_buffer(out, (void**) output_image, (size_t*) output_length, NULL); However, attempting to save this GIF produces all kinds of strange effects depending on the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi again, you need to set the new You don't need to chop into pages and then reassemble -- just pick a scale factor which will get the page boundaries to land in the right place. There's some sample code in the https://github.com/libvips/libvips/blob/master/libvips/resample/thumbnail.c#L782-L791 But I'd just call VipsImage *thumb = vips_thumbnail_buffer(input_data, input_length, target_width,
"option_string", "n=-1",
NULL);
void *data;
size_t length;
vips_gifsave_buffer(thumb, &data, &length, NULL); |
Beta Was this translation helpful? Give feedback.
Hi again, you need to set the new
page_height
so the gif saver knows how to write each page of the output image.You don't need to chop into pages and then reassemble -- just pick a scale factor which will get the page boundaries to land in the right place. There's some sample code in the
thumbnail
sources:https://github.com/libvips/libvips/blob/master/libvips/resample/thumbnail.c#L782-L791
But I'd just call
thumbnail
instead. It'll handle things like premultiply for you too.