Results 1 to 3 of 3

Thread: Animated gif with GD

  1. #1
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Animated gif with GD

    I'm adding a hit counter service to one of my sites, and I want to be able to use animated gif's. This works fine with regular images, but if it's animated, it only uses one frame. Does anyone know how I can make this work properly with an animated gif? Or if it's even possible? Thanks in advance.

    PHP Code:
    <?

    session_start
    () ;

    require_once(
    "config.php") ;
    require_once(
    "functions/functions.php") ;
    $account jc_code($_GET['acc'], 'off''off''name') ;

    if((
    file_exists('data/' $account '.jac')) && (!$account == "")) {
      
    $handle fopen('data/' $account '.jac'r) ;
      
    $content fread($handlefilesize('data/' $account '.jac')) ;
      
    $line_content explode("\r\n"$content) ;
      
    $section_content explode("|"$line_content[0]) ;
      
    fclose($handle) ;
      
    $hits $section_content[3] + ;
      if(
    $_SESSION['last_log'] > time() - 3) {
        
    //cant log yet - too early
      
    }
      
      else {
        
    $_SESSION['last_log'] = time() ;
        
    $section_content[3] = $hits ;
        
    $section_content[4] = time() ;
        
    $handle fopen('data/' $account '.jac'w) ;
        for(
    $a 0$a 11$a ++) {
          
    $write_data .= $section_content[$a] . '|' ;
        }
        
        
    fwrite($handle$write_data) ;
        
    fclose($handle) ;
      }
      
      if(
    file_exists("images/counter/$section_content[1].gif")) {
        
    $img_handle ImageCreateFromGif("images/counter/$section_content[1].gif") ;
      }
      
      else {
        
    $img_handle ImageCreateFromGif("images/counter/default.gif") ;
      }
      
      
    $txt_color imagecolorallocate ($img_handle000) ;

      if(
    strlen($hits) < 2) {
        
    $hits '000' $hits ;
      }
      
      elseif(
    strlen($hits) < 3) {
        
    $hits '00' $hits ;
      }
      
      elseif(
    strlen($hits) < 4) {
        
    $hits '0' $hits ;
      }

      
    $center 155 - ((strlen($hits) * 9) / 2) ;

      
    header("Content-type: image/gif") ;
      
    $font imageloadfont($load_font) ;
      
    Imagestring($img_handle$font$center2$hits$text_color) ;
      
    imagegif($img_handle);
    }

    else {
      
    $img_handle ImageCreateFromGif("images/counter/default.gif") ;  
      
    $txt_color imagecolorallocate ($img_handle000) ;
      
    $text "- - - - -" ;
      
    $center 155 - ((strlen($text) * 9) / 2) ;
      
    header("Content-type: image/gif") ;
      
    $font imageloadfont($load_font) ;
      
    Imagestring($img_handle$font$center2$text$text_color);
      
    imagegif($img_handle);
    }

    ?>

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I have no experience with this myself, but I found this. If it works, let us know.

    http://www.phpclasses.org/browse/package/3163.html

  3. #3
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Unfortunately, that had to do with creating an animated gif using multiple image files as source. I ended up just modifying the script a bit to place the text onto a transparent gif, and using a div to layer that onto an unmodified animated gif. Looks just as good, and allows my users to easily use their own animation or other image, instead of just what I provide. Thanks anyways.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •