Coder Social home page Coder Social logo

gifframeextractor's People

Contributors

sybio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gifframeextractor's Issues

getFramePositions() often zero when they should not be

For about 70% of the transparent GIFs I test, getFramePositions() is returning all zeros. These are transparent GIFs with lots of alpha padding. My understanding is when there is alpha pixel padding getFramePositions() should NOT return zero. Is this correct? Thanks.

Add method to fetch the number of times a gif loops.

Can I request that a method be added which tells you the number of times a gif loops? I'm extracting frames then resizing them and then using your other library (GifCreator) to recompile the frames back into an animated gif.

For the moment I'm setting it to loop indefinitely, but ideally I should specify the number of loops as specified in the source file.

If there's a simple vanilla PHP way of getting the loops then I'm all ears!

Unable to unlink() the source file after extraction

@Sybio
I was unable to delete the source file after extraction. I was getting permission error and that only occur when i use $gifExtract->extract($rawSource);

So i found out it was a permission issue. So i tried

@chmod($rawSource, 465);
@unlink($rawSource);

But what if the code is running on a shared host with chmod restriction.
So I look into the GifFrameExtractor.php file and I found out the file wasn't closed after processing.

So I made a slit tweak by adding $this->closeFile(); and it fix the problem.

private function parseFramesInfo($filename)
    {
        $this->openFile($filename);
        $this->parseGifHeader();
        $this->parseGraphicsExtension(0);
        $this->getApplicationData();
        $this->getApplicationData();
        $this->getFrameString(0);
        $this->parseGraphicsExtension(1);
        $this->getCommentData();
        $this->getApplicationData();
        $this->getFrameString(1);
        
        while (!$this->checkByte(0x3b) && !$this->checkEOF()) {
            
            $this->getCommentData(1);
            $this->parseGraphicsExtension(2);
            $this->getFrameString(2);
            $this->getApplicationData();
        }
        $this->closeFile();
    }

Animated GIF bugged colors

This is a bug reported in ImageWorkshop library but concerning this repository.

Created by @Kekke88 :

Hello, I've been trying to add an image upon a GIF image using your libraries.

However, it turns the gif image into some weird blue color.
I have tried to debug but I can't find what's wrong, I tried using getResult with a background color but it still didn't help.

I printed the frames as images and it seems that image #2 is the first image to get weird colors.

Here is the picture before:
http://i.imgur.com/M3bM7yP.gif

and after:
http://i.imgur.com/lyMu2P0.gif

All the images extracted:
http://imgur.com/2kFqUzw,TAxAjeC,YzM4ztE,alotpAS,CdUTa7a,IQQiylp,BjI14CD,IlrQZiC,mo2vrs1,QPEsR67,ohFZ4sN,xM9jzvC,GyA3Toa,Eepmqhv,O5vxpfc,IE1lKG9,EqP9foq,VAtE7oY,sVsteMd,NtQziAE,YVKMGfz,4GEgyBf,3cvPE7m,hgJtWCt,dbbQSNe,mrBjnRN,MgAbBqi,1i3yhLn,43GUKOu,hkmXP0n,ysajT72#1

Regards

Code sample :

<?php

include 'GifFrameExtractor.php';
include 'GifCreator.php';
include 'ImageWorkshop.php';

$gifPath = 'teac.gif';

if(GifFrameExtractor::isAnimatedGif($gifPath)) {
$gfe = new GifFrameExtractor();
$frames = $gfe->extract($gifPath);

$watermarkLayer = ImageWorkshop::initFromPath('wm.png');

$retouchedFrames = array();
//$it = 0;
foreach ($frames as $frame) {
    $frameLayer = ImageWorkshop::initFromResourceVar($frame['image']);
    $frameLayer->resizeInPixel($frameLayer->width, $frameLayer->height, false);
    $frameLayer->addLayerOnTop($watermarkLayer, 20, 20, 'LB');
    $image = $frameLayer->getResult();

    // Creating all the GIF Images
    //imagejpeg($image, 'test' . $it . '.jpg', 95);
    $retouchedFrames[] = $frameLayer->getResult();
    //$it++;

}
// Then we re-generate the GIF
$gc = new GifCreator();
$gc->create($retouchedFrames, $gfe->getFrameDurations(), 0);
// And now save it !
file_put_contents('newgif.gif', $gc->getGif());
}
?>

Before :
Before

After :
After

Frame Durations

It seems that the frame durations are missing a place.
When I get the frame duration of a 10000ms frame, it returns only 1000.
When I get the frame duration of a 200ms frame, it returns only 20.
Unless I'm mistaken.

Save function

Any chance this class can have a way to save the manipulated frames back out into an animated GIF again?

getTotalDuration returns 0 for a 117 frame GIF?

I'm not even sure this repo is maintained anymore. I sure hope it is, since it could be very useful.

Can anyone please explain why this GIF returns a getTotalDuration() of 0? GifFrameExtractor recognizes it has frames, 117 of them, but it returns a frameDuration of 0 for each, which adds up to 0. -_-

This isn't exactly helpful. I suspect it has something to do with 'Delay Time' vs. 'Unclamped Delay Time', as inspecting it with Preview on Mac shows the former to have a value of 0.1, and the latter to be 0.

Help, ideas?

This GIF complete destroys php instance

In GifFrameExtractor at line 220. Something inside here is causing the entire php instance to crap out, the only way out is to restart PHP. I tried to set a time out but even that doesn't work something is screwy in this file!

        while (!$this->checkByte(0x3b) && !$this->checkEOF()) {

            $this->getCommentData(1);
            $this->parseGraphicsExtension(2);
            $this->getFrameString(2);
            $this->getApplicationData();
        }

q0sqvwl

about GifFrameExtractor not found problem

hello,
I use your code,but it show this problem.

Uncaught Error: Class 'GifFrameExtractor' not found in C:\xampp\htdocs\gites\a.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\gites\a.php on line 5

my GifFrameExtractor.php and gif image and my demo.php is in same folder.
I dont know why it can not found?
this is my code
`
<?php
include("GifFrameExtractor.php");

 $gifFilePath = 'a_g.gif';
 if (GifFrameExtractor::isAnimatedGif($gifFilePath)) { // check this is an animated GIF

$gfe = new GifFrameExtractor();
$gfe->extract($gifFilePath);
$totalDuration = $gfe->getTotalDuration();
 echo $totalDuration;
// Do something with extracted frames ...
}

?>`

please help me ,thanks

Image combining doesn't work properly, fixes described

I downloaded this code because I wanted to be able to extract frames from GIFs, but I found a few problems applying it to some GIFs that used the "Leave" method for image disposal, where it would combine a frame with the previous frame using transparency.

There were two problems --

The first is that it copied the image to the composite sprite using the maximum height and width, like so,
imagecopyresampled($sprite, $img, $this->frameSources[$i]["offset_left"], $this->frameSources[$i]["offset_top"], 0, 0, $this->gifMaxWidth, $this->gifMaxHeight, $this->gifMaxWidth, $this->gifMaxHeight);

However, if the second image was smaller in dimensions than the first, this would effectively black out anything past the dimensions of the first. The compositing would need to be done like this instead,
imagecopyresampled($sprite, $img, $this->frameSources[$i]["offset_left"], $this->frameSources[$i]["offset_top"], 0, 0, $this->frameSources[$i]["width"], $this->frameSources[$i]["height"], $this->frameSources[$i]["width"], $this->frameSources[$i]["height"]);

Of course, that would only be for frames with the "Leave" method; otherwise it makes sense to black it out if the dimensions are kept to the maximum height and width. Though I'm not sure that's how animated GIFs work.

Second, it used the current index to determine the disposal method,
$this->frameSources[$i]['disposal_method']

While the disposal method applies to the previous frame, so needs to be taken from the previous image data. So it needs to be addressed like this,
$this->frameSources[$i-1]['disposal_method']

The project obviously looks like it has a lot left unimplemented and it looks like @Sybio has been gone for a while, but I'm leaving this documented here for anyone that might find interest in it.

Memory leak/issue

There appears to be an issue with memory usage in this script:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 906 bytes) in gifframeextractor.php on line 149

The gif being processed: http://yum.gifsicle.com/0ed0dc3.gif

The gif is only about 2.5Mb so not sure why it is trying to allocate over 64MB.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.