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

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
sriducati
Posts: 28
Joined: 2011-11-28T08:11:59-07:00
Authentication code: 8675308

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

Post 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..
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

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

Post 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");
?>
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Post Reply