Skip to content
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

Issue with loading animated gif file from buffer #22

Open
yellow1912 opened this issue Feb 5, 2022 · 2 comments
Open

Issue with loading animated gif file from buffer #22

yellow1912 opened this issue Feb 5, 2022 · 2 comments

Comments

@yellow1912
Copy link

yellow1912 commented Feb 5, 2022

For some reason, when loading gif from string my loader is VipsForeignLoadNsgifBuffer instead of VipsForeignLoadGifBuffer. The n option is not applied correctly.

The following addition fixes the issue (for now):

protected function getLoadOptions($loader, $loadOptions = [])
    {
        $options = [];
        switch ($loader) {
            case 'VipsForeignLoadJpegFile':
            case 'VipsForeignLoadJpegBuffer':
                $options['autorotate'] = true;
                break;
            case 'VipsForeignLoadHeifFile':
            case 'VipsForeignLoadHeifBuffer':
                $options['autorotate'] = true;
                $options['n'] = -1; // not sure this should be enabled by default, to discuss
                break;
            case 'VipsForeignLoadGifFile':
            case 'VipsForeignLoadGifBuffer':
            case 'VipsForeignLoadNsgifBuffer':
                $options['n'] = -1; // not sure this should be enabled by default, to discuss
                break;
        }
        $options = array_merge($loadOptions, $options);
        // FIXME: remove not allowed options

        if (isset($options['shrink'])) {
            switch ($loader) {
                case 'VipsForeignLoadJpegFile':
                case 'VipsForeignLoadJpegBuffer':
                case 'VipsForeignLoadWebpFile':
                case 'VipsForeignLoadWebpBuffer':
                    break;
                default:
                    unset($options['shrink']);
               }
        }
        return $options;
    }

My current vips config is:

enable debug: no
enable deprecated library components: yes
enable modules: no
use fftw3 for FFT: no
accelerate loops with orc: yes
ICC profile support with lcms: yes (lcms2)
zlib: yes
text rendering with pangocairo: no
font file support with fontconfig:
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: no
PNG load/save with libpng: yes (pkg-config libpng >= 1.2.9)
quantisation to 8 bit: yes
TIFF load/save with libtiff: no
image pyramid save: yes
HEIC/AVIF load/save with libheif: no (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: no
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

Should I send a PR for this fix?

@chregu
Copy link
Contributor

chregu commented Feb 5, 2022

A PR would be fine. I actually never used libnsgif, that may be the issue why I didn't catch it. Somehow strange that there are two different loaders for that, but anyway, easy fix and no potential harm.

@andi-wr
Copy link

andi-wr commented Feb 12, 2024

Somehow strange that there are two different loaders for that, but anyway, easy fix and no potential harm.

See here: https://stackoverflow.com/questions/75772029/vips-warning-error-in-tile-0-x-1104-gif-crashing-website-ruby-on-rails#comment133680071_75777349

libvips used to use giflib for loading GIFs, but switched to the (much better) nsgif loader in 8.11

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

No branches or pull requests

3 participants