Skip to content

add support to thumbnail for cropping animated images #2668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vansante opened this issue Feb 17, 2022 · 6 comments
Open

add support to thumbnail for cropping animated images #2668

vansante opened this issue Feb 17, 2022 · 6 comments

Comments

@vansante
Copy link

vansante commented Feb 17, 2022

Questions, enhancements, tips, etc.

Please use libvips discussions for other topics.

https://github.com/libvips/libvips/discussions

Bug report

Describe the bug
Using vips_thumbnail_image on a GIF with multiple frames and crop set to VIPS_INTERESTING_CENTRE results in a single frame image, while using VIPS_INTERESTING_NONE results in an image with the right amount of frames.

To Reproduce
Steps to reproduce the behavior:

  1. Use Image failgif
  2. Load the image
  3. Use vips_thumbnail_image with width set to 40 and height set to 30 and crop set to VIPS_INTERESTING_CENTRE and VIPS_INTERESTING_NONE.
  4. Save the 2 images to a new GIF file with the new gifsave exporter
  5. Note how one of the images contains all 9 frames and the other has just 1 frame.

Expected behavior
I expect the resulting images to contain all 9 frames.

Actual behavior
The image which had crop set to VIPS_INTERESTING_CENTRE contains just 1 frame.

Screenshots
The resulting images:

  • VIPS_INTERESTING_CENTRE
    crop-failgif

  • VIPS_INTERESTING_NONE
    nocrop-failgif

Environment
(please complete the following information)

  • OS: Ubuntu 20.04
  • Vips:
paul@f11a770d909b:/multimedia$ vips --vips-version
libvips 8.12.2-Tue Jan 25 09:34:32 UTC 2022
paul@f11a770d909b:/multimedia$ vips --vips-config
enable debug: no
enable deprecated library components: yes
enable modules: no
use fftw3 for FFT: yes
accelerate loops with orc: yes
ICC profile support with lcms: yes (lcms2)
zlib: yes
text rendering with pangocairo: yes
font file support with fontconfig: yes
RAD load/save: yes
Analyze7 load/save: yes
PPM load/save: yes
GIF load:  yes
GIF save with cgif: yes
EXIF metadata support with libexif: yes
JPEG load/save with libjpeg: yes (pkg-config)
JXL load/save with libjxl: no (dynamic module: no)
JPEG2000 load/save with libopenjp2: no
PNG load with libspng: yes
PNG load/save with libpng: yes (pkg-config libpng >= 1.2.9)
quantisation to 8 bit: yes
TIFF load/save with libtiff: yes (pkg-config libtiff-4)
image pyramid save: yes
HEIC/AVIF load/save with libheif: yes (dynamic module: no)
WebP load/save with libwebp: yes
PDF load with PDFium:  no
PDF load with poppler-glib: no (dynamic module: no)
SVG load with librsvg-2.0: yes
EXR load with OpenEXR: yes
OpenSlide load: no (dynamic module: no)
Matlab load with matio: no
NIfTI load/save with niftiio: no
FITS load/save with cfitsio: no
Magick package: none (dynamic module: no)
Magick API version: none
load with libMagickCore: no
save with libMagickCore: no

Additional context

@vansante vansante added the bug label Feb 17, 2022
@jcupitt jcupitt added enhancement and removed bug labels Feb 17, 2022
@jcupitt
Copy link
Member

jcupitt commented Feb 17, 2022

Hi @vansante,

vipsthumbnail doesn't attempt to crop animated images, but I agree it's an obvious thing to add.

Let's tag this as an enhancement.

@jcupitt jcupitt changed the title Using vips_thumbnail_image with cropping makes the image lose its frames add support to thumbnail for cropping animated images Feb 17, 2022
@Hpsyche
Copy link

Hpsyche commented Dec 3, 2022

hi, jcupitt. @jcupitt Forgive my stupid question, I tried use C to resize GIF, but it doesn’t work, i only get the first frame (not an animation image), vips_thumbnail_image, vips_resize are the same, how do I need to adjust this code?

Code

int main(int argc, char **argv)
{
  VipsImage *in = vips_image_new_from_file("input.gif", NULL);
  VipsImage *out;

  // if (vips_thumbnail_image(in, &out, 100, "height", 100, "size", VIPS_SIZE_FORCE, NULL))
  if (vips_resize(in, &out, 0.5, NULL))
  {
    return 1;
  }
  vips_image_write_to_file(out, "output.gif", NULL);
  return 0;
}

Environment

Vips version: vips-8.13.3

vips -l | grep gif

VipsForeignLoadNsgif (gifload_base), load GIF with libnsgif, priority=50
VipsForeignLoadNsgifFile (gifload), load GIF with libnsgif (.gif), priority=50, is_a, get_flags, get_flags_filename, header, load
VipsForeignLoadNsgifBuffer (gifload_buffer), load GIF with libnsgif, priority=50, is_a_buffer, get_flags, get_flags_filename, header, load
VipsForeignLoadNsgifSource (gifload_source), load gif from source, priority=50, is_a_source, get_flags, get_flags_filename, header, load
VipsForeignSaveCgif (gifsave_base), save as gif (.gif), priority=0, rgba-only
VipsForeignSaveCgifFile (gifsave), save as gif (.gif), priority=0, rgba-only
VipsForeignSaveCgifBuffer (gifsave_buffer), save as gif (.gif), priority=0, rgba-only
VipsForeignSaveCgifTarget (gifsave_target), save as gif (.gif), priority=0, rgba-only

@jcupitt
Copy link
Member

jcupitt commented Dec 3, 2022

Hello @Hpsyche,

Please open a new discussion for a new question. This issue is just for adding a crop feature to animation thumbnailing.

(don't use thumbnail_image, use plain thumbnail; you need to add "n", -1, to load and thumbnail all frames of the animation; resize is a relatively low-level operation and thumbnail adds logic to handle things like resizing animations)

@AmitSonkhiya
Copy link

AmitSonkhiya commented Jul 26, 2023

+1 for this enhancement.
Animated and cropped GIF/Webp thumbnails are an obvious feature expected from the library.

@doutatsu
Copy link

Is there any progress on this? Quite an important features without which I am unable to switch to Vips from Magick

@jcupitt
Copy link
Member

jcupitt commented Jun 28, 2024

No one has volunteered to do the work, so there's been no progress. PRs very welcome if anyone is able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants