-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enhancement: expose libvips magicksave, requires v8.7.0 #1372
Comments
I expect the forthcoming sharp v0.21.0 to provide a prebuilt libvips v8.7.0. There will need to be a code change in sharp to support the forthcoming *magick save feature of libvips. The prebuilt libvips binaries provided by sharp do not include *magick. To take advantage, you will need to compile your own libvips with support for *magick and install it globally before installing sharp. |
hi @lovell, since the version already released, there are any apis for manipulating (like adding frames, setting gif options) with gif files? |
@hbakhtiyor No, not yet. Happy to accept/help with a PR if you're able. |
don't know c++ |
Does this mean if libvips is compiled with *magick, it will work out of the box with sharp? @lovell it would be great if you can elaborate which features are available out of the box and which features will need some code modification in sharp. |
@adityapatadia This issue exists to track the future possible work required to expose libvips' magicksave feature; it will not work "out of the box". |
Okay then I think I would wait for it. Libvips 8.8 has save GIF as WebP feature as well. It would be great to have the same in Sharp as well. |
@lovell Any news on this? I can try to create a PR as this is currently a blocker for us. However, a small hint to point us into the right direction could really help 😉 |
A possible API to expose vips_magicksave and vips_magicksave_buffer might look like: sharp(input)
.magick(format) // POSSIBLE API, NOT YET AVAILABLE
.toBuffer() where However since everyone commenting here is really after GIF output, then an initial and easier to understand API might be: sharp(input)
.gif() // POSSIBLE API, NOT YET AVAILABLE
.toBuffer() which might also be a tiny bit easier to implement/test too. Filesystem-based output would also need to be made possible, so the following would need to be made to work: sharp(input)
.toFile('out.gif') // POSSIBLE API, NOT YET AVAILABLE In terms of implementation hints, start by looking at an existing function that controls output format such as |
@lovell We implement the basic GIF support. It was necessary to install the We decided to test it in our product before we create PR but we need to deploy it into The problem is that it constantly complains about missing So, as we are going to introduce the GIF support, someone will need to compile vendor libs with Do you think that you are able to do it for us before we create the PR into In that case, we will have the support for it in vendor but sharp itself will not use it until we introduce the GIF support? |
@deftomat Thanks for investigating and working on this.
The ability to save via *magick will follow the same pattern as other features requiring a custom libvips such as output options relating to mozjpeg or libimagequant. |
Thanks, we will figure it out then 😉 |
@deftomat If you have a work-in-progress branch I could take a look at I would love to see where you are at and maybe hack on a it a bit myself |
@raphaeleidus |
@deftomat hope you had a good holiday. If you are back I would love to take a look at your progress |
@raphaeleidus I apologise to everyone, who is waiting for a GIF support, that I was still not able to create a proper PR. We spend a lot of time integrating this into our systems and building a custom VIPS with IM support for AWS Lambda is a real pain 😞 Anyway, this works for us quite smoothly but there are a few quirks which you need to keep in mind:
I need to add tests and then, we should be ready for a proper PR. Hopefully this or next week. |
Hi all, thanks for working on this issue. I'm not really a specialist in terms of compiling libs, will somebody tell me exactly what do I have to do to get fully working support for animated gif (taking modification from @deftomat )? It would be really great to take as an example scenario with fresh ubuntu 16 installation with node 10 on board. one more thanks for hard working on this |
@wojtekelvis Here is an excerpt from Dockerfile we use for our application: FROM node:10-slim
# Install libraries and programs
RUN true \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# needed for building
automake build-essential \
# libvips image libraries
libjpeg-dev libtiff-dev libpng-dev libgif-dev librsvg2-dev libpoppler-glib-dev zlib1g-dev fftw3-dev liblcms2-dev \
libmagickwand-dev libpango1.0-dev libexif-dev liborc-0.4-dev libwebp-dev \
# needed to rebuild sharp against global libvips
python \
# custom allocator to preserve rss memory
libjemalloc1 \
&& apt-get autoremove -y \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& true
COPY ./lib/vips-8.7.3.tar.gz /tmp/
# Build libvips
RUN true\
&& cd /tmp \
&& tar zxvf vips-8.7.3.tar.gz \
&& cd /tmp/vips-8.7.3 \
&& ./configure --enable-debug=no $1 \
&& make -j4 \
&& make install \
&& ldconfig \
&& rm -rf /tmp/* /var/tmp/* \
true
# Change memory allocator to avoid rss leaks
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1 You need to download vips sources from here and put them in ./lib directory relative to Dockerfile: |
@OJezu thank you very much! |
@wojtekelvis when you create the |
Also, keep in mind that VIPS is using ImageMagick to save GIFs. So, ImageMagick must be available before you build the VIPS. |
@raphaeleidus thanks for suggests ,but what I'm currently trying to do is to create a readable stream and then pipe it to sharp. In this scenario first param for constructor which is input have to be string or buffer which is not the case. Do you have any solution to this ? or maybe Im missing something really easy. @deftomat thanks for remind, using dockerfile attached above by @OJezu so from what I see, there is a plenty of dependencies install in first RUN, do I have to add something more to this to be able to get working animated GIF ? |
@wojtekelvis I'm not sure if |
@deftomat hm, was able to create animated gif! hurra my simple scenario looks like this:
but Is there something I can do to speed this up ? |
Well, currently, we are loading the image just like a toilet paper (VIPS limitation). So, frames are joined into one big image. To do any transformations, you need to extract each frame ( Then, when you are saving it with a proper To be honest, I'm not sure if we even want to support simple resize operation as extract/composite combination provides an infinite amount of flexibility. Even adding/removing the frame is easily doable as you are working with one big image. |
After all these discussion, I think we still don't have a reliable way to resize GIF via sharp. It's also hard to convert GIF images to WebP in a reliable way via Sharp. Currently only reliable way to process GIF images is via gifsicle. We have created this module to resize GIF files: https://www.npmjs.com/package/@gumlet/gif-resize I think it would still be hugely beneficial if we can properly add support for GIF in sharp. If someone guides us on how to implement it, may be we can spend some time on this. |
Support for WEBP & GIF animations: #2012 |
sharp v0.30.0 now supports GIF output using the prebuilt binaries so I'll close this issue, thanks all. |
Loads of thanks <3 |
Currently, there's lack of support of
.gif
format by the library, but it will be supported by underlyinglibvips
in v8.7.0 (see release notes for https://github.com/jcupitt/libvips/releases/tag/v8.7.0-rc1 and https://github.com/jcupitt/libvips/issues/839libvips magicsave
for .gif output).We integrated
sharp
in Ghost lately and would be lovely to have gifs support for our image uploads(TryGhost/Ghost#9848)
Cheers Lovell! And let me know if I could be helpful in testing etc.
The text was updated successfully, but these errors were encountered: