sybio / gifcreator Goto Github PK
View Code? Open in Web Editor NEWGifCreator is a PHP class that creates animated GIF from multiple images
GifCreator is a PHP class that creates animated GIF from multiple images
I'm using a Wordpress plugin that uses this and GifFrameExtractor to resize animated GIFs. For the most part it works great but with certain GIFs, visual errors are introduced in the resized versions.
Here's an example:
I know you're not responsible for the Wordpress plugin, but I'm just trying to figure out what's going on. The errors seem to be consistent - ie, if I resize the image multiple times the errors in the resized versions look exactly the same.
I can provide more examples if it would help figure out the problem. It seems more likely to happen when there are large sections of a single color (in this case white).
I can't get this to work at all, is it still functioning? Any real world examples?
$gc->create($frames, $durations, LOOP);
define('LOOP', 0);
or
define('LOOP', FALSE);
But image still looped.
Warning: imagecreatefromstring(): gd-png: fatal libpng error: Read Error: truncated data in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113
Warning: imagecreatefromstring(): gd-png error: setjmp returns error condition in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113
Warning: imagecreatefromstring(): Passed data is not in 'PNG' format in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113
Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 113
Fatal error: Uncaught exception 'Exception' with message 'GifCreator: Under development: 171 Source is not a GIF image.' in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php:132
Stack trace:
#0 /Users/Flo/GitHub/whiteboard-comics/test.php(23): GifCreator\GifCreator->create(Array, Array, 0)
#1 {main}
thrown in /Users/Flo/GitHub/whiteboard-comics/GifCreator.php on line 132
Dont work if pass paths? work only with imagecreatefrom()...
find better way
$GIF = new Imagick();
$GIF->setFormat("gif");
for ($i = 0; $i < sizeof($gifFrames); ++$i) {
$frame = new Imagick();
$frame->readImage($gifFrames[$i]);
$frame->setImageDelay(100);
$GIF->addImage($frame);
}
Imagick === No memory leak
When I load 2 PNGs with transparent backgrounds, it changes to black.
I use small code change from (PNG to GIF converter - https://gist.github.com/gesior/6f5f7d15cb50f59a88fd) and now it works fine for PNGs. Before you add it, you must check, if other coversions still works fine.
Modified part of script:
} elseif (is_string($frames[$i])) { // File path or URL or Binary source code
if (file_exists($frames[$i]) || filter_var($frames[$i], FILTER_VALIDATE_URL)) { // File path
$frames[$i] = file_get_contents($frames[$i]);
}
$resourceImg = imagecreatefromstring($frames[$i]);
$background = array(255, 255, 255);
$width = imagesx($resourceImg);
$height = imagesy($resourceImg);
$image = imagecreatetruecolor($width, $height);
imagefill($image, 0, 0, $bgcolor = imagecolorallocate($image, $background[0], $background[1], $background[2]));
imagecopyresampled($image, $resourceImg, 0, 0, 0, 0, $width, $height, $width, $height);
imagecolortransparent($image, $bgcolor);
ob_start();
imagegif($image);
$this->frameSources[] = ob_get_contents();
ob_end_clean();
imagedestroy($image);
} else { // Fail
EDIT:
I did test it with these PNG as resources.
When I use 'imagepng', it save them with transparent background.
When I use 'imagegif', it save them with black background.
There must be something bad with PHP library that saves same image resource with/without transparency.
HI,
I found that after create any gif with transparence the new gif in transparent part has black layers moving.
@Sybio did you see this problem before? Could you solve this?
Thank you!
Regards
I have tested much times making gif from 11 jpg/jpeg images,the result is too large over 450kb.
Does GifCreator
has some options or method to compress gif file?
Thanks a lot!
Dear sir!
Please check this post.
https://stackoverflow.com/questions/45927081/gif-creator-from-array-images-in-php
Deprecated: Array and string offset access syntax with curly braces is deprecated in GifCreator.php on line 135.
Using PHP 7.4.2
Error can be fixed by replacing { 10 } with [10] in the code at several lines;
Hi
Can you create a tagged stable version number in git please so that I can use your library in composer without setting the minimum-stability
flag to dev
?
Thanks ;)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.