image icon indicating copy to clipboard operation
image copied to clipboard

¿Animated GIF support?

Open Gelurban opened this issue 11 years ago • 37 comments

Hello, I was wondering to know if it is possible to get and save an animated GIF, since when I try:

Image::make('mygif.gif')->save('images/mygif.gif);

It will become a "static" image, losing the animation.

Thanks in advance

Gelurban avatar Jul 05 '14 22:07 Gelurban

It's not possible at the moment, but would be nice to have.

olivervogel avatar Jul 07 '14 14:07 olivervogel

I also wanted this feature.

For now, you can use another function to save when it is a gif, and keep using others from the library.

$image = Image::make($file->getRealPath());

if ($file->getClientOriginalExtension() == 'gif') {
    copy($file->getRealPath(), $destination);
}
else {
    $image->save($destination);
}

$width = $image->width();
$height = $image->height();
$image->destroy();

marcoflorian avatar Oct 13 '14 09:10 marcoflorian

A great suggestion. At the moment I'm just copying the resource, but it'll be great to be able to crop an animated gif.

kevinruscoe avatar Apr 15 '15 18:04 kevinruscoe

As I understand this feature is already present in development branch. (I've forked repo and merged master into development and checked this functionality in laravel app I'm currently working on) @olivervogel can you comment on when you plan to release it. I see tag nextversion on this issue but not sure what it exactly means.

loginwashere avatar Apr 23 '15 09:04 loginwashere

The development branch represents what will be the next major version (3.x). But it is currently under development and I would not use the branch for anything than development at all. Tag nextversion means that this feature will be available in the next major version.

Currently there is no release date. This is a free open source project and I'm working on it in my spare time.

olivervogel avatar Apr 23 '15 10:04 olivervogel

@olivervogel thanks for clarification

loginwashere avatar Apr 24 '15 09:04 loginwashere

What is the current status here?

philippzentner avatar Jun 05 '15 17:06 philippzentner

make sure to use strtolower() on getClientOriginalExtension() as some images may have different casing on file extensions.

bubjavier avatar Apr 19 '16 20:04 bubjavier

https://github.com/glukash/glu-image

support only laravel 4

need laravel 5.2 help me please

revi4n4 avatar Apr 22 '16 23:04 revi4n4

system("convert big.gif -coalesce coalesce.gif"); system("convert -size 200x100 coalesce.gif -resize 200x10 small.gif");

revi4n4 avatar Apr 23 '16 00:04 revi4n4

Keep GIF animation for Imagick:

$im = new \Imagick('path/to;image');

if ($im->getImageFormat() == 'GIF') {
    $im = $im->coalesceImages();

    do {
        $im->resizeImage($resize['width'], $resize['height'], \Imagick::FILTER_BOX, 1);
    } while ($im->nextImage());

    $im = $im->deconstructImages();
} else {
    $im->resizeImage($resize['width'], $resize['height'], \Imagick::FILTER_LANCZOS, 1, true);
}

$im->writeImages('some/path/to', true)

For GD check animation:

function is_animated($filename)
    $filecontents = file_get_contents($filename);

    $str_loc = 0;
    $count = 0;
    while ($count < 2) { // There is no point in continuing after we find a 2nd frame

        $where1 = strpos($filecontents, "\x00\x21\xF9\x04", $str_loc);
        if (!$where1) {
            break;
        } else {
            $str_loc = $where1 + 1;
            $where2 = strpos($filecontents, "\x00\x2C", $str_loc);
            if (!$where2) {
                break;
            } else {
                if ($where1 + 8 == $where2) {
                    ++$count;
                }
                $str_loc = $where2 + 1;
            }
        }
    }

    return $count > 1;
}

Maybe can help on slipt a GIF image: http://stackoverflow.com/a/12553165/4367683

More info: http://stackoverflow.com/a/718500/4367683

For animated GIFs, the Lib should split them before each method calls and iterates the frames, doing the action foreach one.

odahcam avatar Mar 09 '17 15:03 odahcam

Any News?

NeilSeligmann avatar Apr 01 '17 00:04 NeilSeligmann

Any update for animated GIFs,?

diz123 avatar May 08 '17 10:05 diz123

Still gif images are not supported

adumskis avatar May 10 '17 08:05 adumskis

Perhaps make a pull request to help them out, if this is so important?

HMAZonderland avatar Aug 26 '17 10:08 HMAZonderland

Up

YOzaz avatar Sep 04 '17 11:09 YOzaz

Yeah i'm in too.

idevin avatar Sep 26 '17 13:09 idevin

The code a pasted above is not usefull?

odahcam avatar Sep 26 '17 14:09 odahcam

Thanks, it's usefull!

idevin avatar Sep 26 '17 14:09 idevin

Image GD class that supports GIF manipulation: https://gist.github.com/odahcam/e7255f406e02ddf390080bf3add2cd43#file-imagegd-php-L4

odahcam avatar Sep 27 '17 04:09 odahcam

Any plans for this? Gifs are a big part of the web these days...

scottybo avatar Jan 05 '18 14:01 scottybo

Any update on this? :)

scottybo avatar Nov 15 '18 10:11 scottybo

@olivervogel You mention above a development branch, but I can't seem to find it anywhere. Is it public? If so, where might one find it? And of course, thanks for this great package!

MegaphoneJon avatar Jan 07 '19 03:01 MegaphoneJon

Thanks @marcoflorian

kennyalmendral avatar May 01 '19 18:05 kennyalmendral

I am interested in this one as well. I see only the first frame is captured on resize, so for now will just copy GIF resources.

brandonburkett avatar Jul 03 '19 19:07 brandonburkett

@olivervogel, I know this is ancient, but are you still able to link to the development code that was referenced above? I'm not seeing anything anymore except for a master and a 1.6 branch in this repository. I'm asking because I'd like to potentially expand upon what's already built, if possible (since I need this for something I'm working on and may need to move to intervention/image myself in the future, i.e. SilverStripe v4). So, if we can incorporate this as core functionality (at least with Imagick) I may be interested.

For what it's worth: This is the first time I've looked at intervention/image. However, digging deeper into how this would work in Imagick at least, I think this has probably lagged behind a bit, since working with an animated gif seems to require that you basically iterate over every single frame as it's own separate instance of Imagick (a child of the parent instance) and then and apply the defined transformations repeatedly (e.g. ->resize(), ->resizeCanvas(), ->fit() and etc.) before being merged back together as a single image (i.e. the final encoded blob/file, per the internal API). I'm not sure how this would be accomplished internally within this library, but I could see how that might require yet another layer of abstraction/complexity. For example, maybe one could ensure that if this is an animated gif (e.g. Imagick->count() > 0) you would wrap the execution of commands in an iteration that would be called on a cached result of Imagick->coalesceImages(). I don't know; I haven't actually used this library yet, but I will someday 😄.

patricknelson avatar Jul 01 '20 03:07 patricknelson

Still interested in animated gif support, this package is almost perfect, the lack of gif support does hurt though!

lewislarsen avatar Jul 18 '20 03:07 lewislarsen

Still interested in animated gif support, this package is almost perfect, the lack of gif support does hurt though!

As previous fella. :)

wiejakp avatar Sep 05 '20 06:09 wiejakp

How is this still not a thing?

Snakzi avatar Oct 13 '20 20:10 Snakzi

Is anybody actively working on this? Has there been any work done on this? Is there a branch that I could pick up? What's stopping it? Complexity and/or lack of developer motivation? Technical hurdles?

mrchimp avatar Oct 22 '20 12:10 mrchimp