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
Support for Animated GIF #18
Comments
Hm, interesting. Let me review the docs for this and I’ll spec something out as I have not used this functionality before, but it shouldn’t be too difficult to add in.
|
I have found the following implementation for lua based gd FFI bindings, which might be interesting for reference purposes: https://github.com/kwanhur/lua-resty-gd/blob/403dd3a0a78a0444a8b50aa8d0a26cb04825e5a9/lib/resty/gd/image.lua#L1070-L1167 Perl: https://metacpan.org/pod/GD::Image::AnimatedGif |
Alright, I’ll try to take a look at this on the weekend and see if I can implement.
|
I've started work on this and have begun the implementation and have everything partially working, but I need to a) get the actual image to render correctly, as at the moment I can see that the data is there but for some reason I get only a black image, i.e. the file itself contains all of the frames it should but for whatever reason won't actually produce a correct file; and b) prepare a sane API. Right now it's fairly unintuitive -- it would be nicer to have a simple wrapper similar to how the Perl library does things. In any event, it's "working", and hopefully will be ready to use Real Soon Now. |
Did you manage to solve the problem with rendering these animated gifs? And is there anything that we can help with or try out? |
I did write some code for this feature bur haven’t it’s still rough and I’m not thrilled about the API. I’d be able to put some more time against this in two weeks after I wrap up a work release if still interested.
|
@dark-panda Yes, we're very much still interested! Again, if you want help testing or anything, just let me know. |
Looking at the Perl way of doing things, they seem to be calling a gifanimbegin, followed by multiple gifanimadds, and eventually a gifanimend:
I wonder if we could do something similar and collect the result like done in $gifdata above: ptr below would refer to an Image object: (totally untested)
|
That’s similar to what I had partially written but I’ll use this as a guide. Mine was “working” but only produced a gif of the correct size as the requested image, but the frames weren’t getting inserted properly. I’ll take a look at this with improved vigor.
|
I did some experiments with the following patch:
Test code:
produces: |
Looking at this now. Looks pretty good. I'm going to wrap this into a class and make a few adjustments, but this is looking pretty good! |
Alright folks, what do you think of https://github.com/dark-panda/gd2-ffij/tree/animated-gif ? I took the code from the pull request and restructured it into a class rather than using singleton methods. The API looks something like this: anim = GD2::AnimatedGif.new
anim.add(image1)
anim.add(image2, delay: 50)
anim.add(image1, delay: 50)
anim.end
anim.export('filename.gif') You can use any IO-style object in output = StringIO.new
anim.export(output)
output.read That way you can avoid writing to disk as necessary, and, say, stream the output to a HTTP response or whatever. I've included a quick test, but if this API looks good, then I'll improve upon it and flesh it out a bit more. |
Released in 0.4.0. |
Thanks! By the way, we’ve noticed a small issue with the sequence of the frames, which we solved by adding the first frame twice - just to make your code behave exactly the same way as my initial example. Works fine in production since a few weeks! See openstreetmap/openstreetmap-website#2204 (comment) for more details. |
Cool, is there anything that should be done on my end, or is this just the nature of GD2? Also, are these traces available for viewing on the site, or is this an admin-only or otherwise non-user facing feature? I just want to see these things in action to see what they look like. |
I think at one point the docs could include a hint that the very first “add” is just setting some animated gif marker and you would still need to add all frames afterwards. Libgd2 has a bit of an interesting API here. All animations are public, you can see them by navigating to each one of the gpx traces: https://www.openstreetmap.org/traces It may not look super fancy, but having animated gif available in Rails helped us getting rid of an external legacy import tool, which lacked essential bits like i18n and was difficult to manage from an operations POV. |
I just wanted to add my thanks to @mmd-osm and @dark-panda for your work in adding animated gif support. We're using it to generate thousands of images per week. As @mmd-osm describes, it was a key part of a larger project to help openstreetmap. Thank you! |
In the context of openstreetmap/openstreetmap-website#281 we're currently evaluating if a gd2 ruby library could be used to generate some rather simplistic animated gif, like the following example:
libGD exposes a few relevant functions (https://libgd.github.io/manuals/2.2.5/files/gd_gif_out-c.html). which unfortunately don't seem to be included in gd2-ffij yet. From an FFI point of view, we're probably looking at adding a few entries. However, it's not quite clear, which approach you would prefer to model the respective ruby classes.
The text was updated successfully, but these errors were encountered: