You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: