Page 1 of 1

very small correction required for this code.. can you fix??

Posted: 2011-12-22T06:45:59-07:00
by sriducati
Hello Webmasters,

this is the IMagick code to create moving text image ...

Code: Select all

<?

    /*** a new Imagick object ***/ 
    $aniGif = new Imagick();
 
    /*** set the image format to gif ***/
    $aniGif->setFormat( "gif" );
 
    /*** a new ImagickPixel object for the colors ***/
    $color = new ImagickPixel( "white" );
 
    /*** set color to white ***/
    $color->setColor( "white" );
 
    /*** the text for the image ***/
    $string = "write what ever";
 
    /*** a new draw object ***/
    $draw = new ImagickDraw();
 
    /*** set the draw font to helvetica ***/
    $draw->setFont( "arial.ttf" );
 
    /*** loop over the text ***/
    for ( $i = 0; $i <= strlen( $string ); $i++ )
    {
        /*** grab a character ***/
        $part = substr( $string, 0, $i );
 
        /*** create a new gif frame ***/
        $aniGif->newImage( 100, 50, $color );
 
        /*** add the character to the image ***/
        $aniGif->annotateImage( $draw, 10, 10, 0, $part );
 
        /*** set the frame delay to 30 ***/
        $aniGif->setImageDelay( 30 );
    }
 
    /*** write the file ***/
    $aniGif->writeImages('ani.gif', $out);


 
?>
it is not creating "ani.gif" but it is creating list of images from "ani-0.gif" to "ani-9.gif" ....yes looks very simple... but still not working??? can any one fix this??? waiting for your response asap..

Re: very small correction required for this code.. can you f

Posted: 2012-01-10T21:50:55-07:00
by DJ Mike
writeImages() has two parameters. The first is the file name, the second determines if you get a multi-file out put like you got or a single file like you want. The second perimeter is Boolean. If TRUE then multi; if FALSE then single file. In your script the second perimeter is $out and since you don't give it a value it is FALSE. Set it to FALSE and you'll get the single file:

$aniGif->writeImages('ani.gif', TRUE);

Imagick::writeImages
http://www.eclecticdjs.com/mike/tutoria ... images.php

Code: Select all

<?
 /*** a new Imagick object ***/
$aniGif = new Imagick();

 /*** set the image format to gif ***/
$aniGif->setFormat( "gif" );

/*** a new ImagickPixel object for the colors ***/
$color = new ImagickPixel( "white" );

/*** set color to white ***/
$color->setColor( "white" );

/*** the text for the image ***/
$string = "write what ever";

/*** a new draw object ***/
$draw = new ImagickDraw();

/*** set the draw font to helvetica ***/
$draw->setFont( "Arial.TTF" );

/*** loop over the text ***/
for ( $i = 0; $i <= strlen( $string ); $i++ )
 {
 /*** grab a character ***/
 $part = substr( $string, 0, $i );

 /*** create a new gif frame ***/
 $aniGif->newImage( 100, 50, $color );

 /*** add the character to the image ***/
 $aniGif->annotateImage( $draw, 10, 10, 0, $part );

 /*** set the frame delay to 30 ***/
 $aniGif->setImageDelay( 30 );
 }

/*** write the file ***/
$aniGif->writeImages('ani.gif', TRUE);

header("Location:ani.gif");
?>