Skip to content
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

Gif animation #12

Closed
walidjlidi opened this issue Mar 19, 2014 · 17 comments
Closed

Gif animation #12

walidjlidi opened this issue Mar 19, 2014 · 17 comments

Comments

@walidjlidi
Copy link

Is it possible to background fill of an animated gif file with a png file usign this library (Use GIF as watermark image.). If is possible can you precise which function i have to use?

the result will be like this http://www.css-101.org/articles/two-layer-image/animated-gif-with-a-jpg-background.php

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

GDEnhancer only support animated GIF as a background , animated GIF will lose animation as a watermark.
Reasons:

  1. GIF doesn't support alpha channel (no semi-transparent)
  2. PNG has alpha channel (support semi-transparent)
  3. If you want use animated GIF as a watermark, to keep the whole image's animation, the output image should be GIF format.
  4. You will encounter problems when watermarking a semi-transparent PNG image, the semi-transparent area will become ugly.
    b09oz
    I recommend:
    It is better to keep the image's original format, never use animated GIF as a watermark, even some scripts support the feature.

@walidjlidi
Copy link
Author

I' m totally agree with you but application requirements demand to
watermark a png by an animated gif file and the result is an animated gif
file. Can you please help with a script make this tip. I try to write this
operation from scratch but result is a very slow operation.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

Sorry, I would help but this is a very complicated task, even Photoshop doesn't support animated GIF as a layer. I need to change the whole mechanism that GDEnhancer work.
I will add this feature in the second version in GDEnhancer, but in months later.
Even GDEnhancer support this in the future, it will costs a lot more more server resource than usual, again, not worth it.

@walidjlidi
Copy link
Author

Thank you for help. Have you some solution to optimize code?
i want to accelerate this task . Just ideas.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

So your watermark is animated GIF, how about your background image? Is it PNG only or perhaps another animated GIF?

@walidjlidi
Copy link
Author

i take a transparent animated gif file and i want to add a png file as a
background to this gif.that's all.

In my code i split gif into separate frame and i water mark the png file by
those frame and transform new frames to a new animated gif.

But this operation demand a lot of ressource. Tell me if you want to take a
look to php function ?

2014-03-19 15:15 GMT+02:00 Xianghan Wang notifications@github.com:

So your watermark is animated GIF, how about your background image? Is it
PNG only or perhaps another animated GIF?

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38048598
.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

Sure, you can paste your code here, or send me through email if you wanna keep the code private.

my email: coldume[at]gmail[dot]com

@walidjlidi
Copy link
Author

No problem i paste my code here :

open($imagebg) ->resize(new Box(600, 600)) ->save('assets/'.$id.'/try/bg.png'); //extract gif & rezize layers $i = 0; foreach ($imagine->open($gif)->layers() as $layer) { $layer->resize(new Box(450, 450))->save("assets/".$id."/try/frame-$i.png"); $i++; } //*************************** header('Content-Type: image/png'); // Create the image $im = imagecreatefrompng('assets/'.$id.'/try/bg.png'); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); //imagefilledrectangle($im, 0, 0, 399, 29, $grey); // The text to draw //$text = 'Testing...'; // Replace path by your own font path $font = 'php/oneway.ttf'; // Add some shadow to the text imagettftext($im, 60, 0, 600, 800, $white, $font, $text); // Add the text imagettftext($im, 45, 0, 150,550, $white, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im,'assets/'.$id.'/try/bg.png'); imagedestroy($im); //************************** //past gif file on background use gdenhancer\GDEnhancer; include_once 'php/gdenhancer/GDEnhancer.php'; for ($c =0; $c < $i; $c++) { $imagee=null; $save=null; $imagee = new GDEnhancer("assets/".$id."/try/bg.png"); $imagee->layerImage("assets/".$id."/try/frame-$c.png"); $imagee->layerMove(0,'topcenter',0,0); $save = $imagee->save(); header('content-type:'.$save['mime'] ); $filename = "assets/".$id."/try/frame-$c.png"; file_put_contents($filename, $save['contents']); imagedestroy($imagee); } //implde a gif file $image = $imagine->open("assets/".$id."/try/frame-0.png"); $layers = $image->layers(); for ($c = 1; $c < $i; $c++) { $layers[] = $imagine->open("assets/".$id."/try/frame-$c.png"); } $name = date("Y-m-d_H-i-s").'.gif'; $image->save("assets/".$id."/try/".$name, array( 'animated' => true, 'animated.delay' => 150, // delay in ms 'animated.loops' => 0, // number of loops, 0 means infinite )); imagedestroy($image); for ($c = 0; $c < $i; $c++) { unlink("assets/".$id."/try/frame-$c.png"); } unlink("assets/".$id."/try/bg.png"); echo '

'.$_POST[

' ;/\* / */ ?>

2014-03-19 16:03 GMT+02:00 Xianghan Wang notifications@github.com:

Sure, you can paste your code here, or send me through email if you wanna
keep the code private.

my email: coldume[at]gmail[dot]com

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38053464
.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

May I know what is the size(in KB) of the original PNG image and the size of output GIF?
By the way, imagedestroy($imagee); is not needed. As $imagee is not a GD resource, and GDEnhancer will destroy GD handler automatically.

@walidjlidi
Copy link
Author

In javascript, user can't upload file up than 2 mo.
and i'm not making any restriction about gif file. Until now, the average
of size of gif file uploaded is 1 mo.

2014-03-19 16:41 GMT+02:00 Xianghan Wang notifications@github.com:

May I know what is the size(in KB) of the original PNG image and the size
of output GIF?
By the way, imagedestroy($imagee); is not needed. As $imagee is not a GD
resource, and GDEnhancer will destroy GD handler automatically.

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38058102
.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

I mean, dose your code run successfully? What is the image size of the test image and output image?

@walidjlidi
Copy link
Author

if i run this code with recommended image size it take one minute to
generate gif file.

2014-03-19 16:59 GMT+02:00 Xianghan Wang notifications@github.com:

I mean, dose your code run successfully? What is the image size of the
test image and output image?

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38060380
.

@walidjlidi
Copy link
Author

that's why i try to optimize my code to generate the gif file in a short
duration.

2014-03-19 17:03 GMT+02:00 walid Jlidi walid.jlidi89@gmail.com:

tha

2014-03-19 17:03 GMT+02:00 walid Jlidi walid.jlidi89@gmail.com:

if i run this code with recommended image size it take one minute to

generate gif file.

2014-03-19 16:59 GMT+02:00 Xianghan Wang notifications@github.com:

I mean, dose your code run successfully? What is the image size of the

test image and output image?

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38060380
.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

So your code is working, can you link original image and the output image?

@walidjlidi
Copy link
Author

can you please explain more ?

2014-03-19 17:07 GMT+02:00 Xianghan Wang notifications@github.com:

So your code is working, can you link original image and the output image?

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38061481
.

@coldume
Copy link
Owner

coldume commented Mar 19, 2014

I have never use imagine before, so I can't help too much. Try to insert microtime(true); on different location of your code. And find what part of your code takes more time to run. Let me know if you find it. :)

@walidjlidi
Copy link
Author

Ok i will do this.

2014-03-19 17:34 GMT+02:00 Xianghan Wang notifications@github.com:

I have never use imagine before, so I can't help too much. Try to insert
microtime(true); on different location of your code. And find what part of
your code takes more time to run. Let me know if you find it. :)

Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-38065274
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants