Page 1 of 1

mergegif class. how do I use it?

Posted: Mon Aug 03, 2009 2:30 am
by psychotomus
anyone know how to use the mergegif class?

Re: mergegif class. how do I use it?

Posted: Mon Aug 03, 2009 4:45 am
by turbolemon
Do you mean this: http://phpclasses.sgboards.com/browse/package/3163.html?

If so, there is a reasonably well commented file called example.php. Here's it's content:

Code: Select all

<?php
include "GIFEncoder.class.php";
/*
    Build a frames array from sources...
*/
if ( $dh = opendir ( "frames/" ) ) {
    while ( false !== ( $dat = readdir ( $dh ) ) ) {
        if ( $dat != "." && $dat != ".." ) {
            $frames [ ] = "frames/$dat";
            $framed [ ] = 5;
        }
    }
    closedir ( $dh );
}
/*
        GIFEncoder constructor:
        =======================
 
        image_stream = new GIFEncoder   (
                            URL or Binary data  'Sources'
                            int                 'Delay times'
                            int                 'Animation loops'
                            int                 'Disposal'
                            int                 'Transparent red, green, blue colors'
                            int                 'Source type'
                        );
*/
$gif = new GIFEncoder   (
                            $frames,
                            $framed,
                            0,
                            2,
                            0, 0, 0,
                            "url"
        );
/*
        Possibles outputs:
        ==================
 
        Output as GIF for browsers :
            - Header ( 'Content-type:image/gif' );
        Output as GIF for browsers with filename:
            - Header ( 'Content-disposition:Attachment;filename=myanimation.gif');
        Output as file to store into a specified file:
            - FWrite ( FOpen ( "myanimation.gif", "wb" ), $gif->GetAnimation ( ) );
*/
Header ( 'Content-type:image/gif' );
echo    $gif->GetAnimation ( );
?>
Lines 6-14 open up and read a directory called frames which is relative to the cwd() of the script (skipping the unix . and .. hard-links), into an array of filenames (and delays on a per-frame basis).

Lines 28-35 instantiate the object, using the parameters defined in the comment.

Line 48 outputs the animation.

Re: mergegif class. how do I use it?

Posted: Mon Aug 03, 2009 4:50 pm
by psychotomus
looks like id rather use Image Magick. I can see its installed on my server but the following code i got from a site to test if it works doesn't work..

Code: Select all

<?php
 
header('Content-type: image/png');
 
$image = new Imagick('data/games/1-9.png');
 
// If 0 is provided as a width or height parameter,
// aspect ratio is maintained
$image->thumbnailImage(100, 0);
 
echo $image;
 
?>

Fatal error: Class 'Imagick' not found in /home/tactical/public_html/demo/imagictest.php on line 21



do I need a class for it or should it allready be installed? IF I need a class, where can I download it.

Re: mergegif class. how do I use it?

Posted: Tue Aug 04, 2009 4:45 am
by turbolemon
Do you get any error messages? As far as I can tell, you can't install the PECL module without the prerequisite binary installed (the module provides the class definitions you use in your PHP code, which is a wrapper for the binary installed on the system). http://php.oregonstate.edu/manual/en/intro.imagick.php

I don't have any experience using ImageMagick to be honest, all my image manipulation has been written for GD. It's one of those things that I have never got round to experimenting with!