SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: gif problem

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Location
    London, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question gif problem

    EEK! Sorry, I wanted to post this in "Build An Automated PHP Gallery System In Minutes" comments thread...could someone move it? Thanks!

    Hi all,

    Seems like a great script, but I'm fairly new to the problems of manipulating MIME types in PHP, so any help with my problem would be very appreciated.

    First off, I'm using PHP 4.3.3 with GD build 2.0.15 (GIF read enabled). The image upload works fine with JPG's, but when I try to upload a GIF file, I get the following error:

    Fatal error: Call to undefined function: imagegif() in c:\appserv\www\gallery\upload.php on line 83

    My upload.php script (which I've hardly changed) is as follows:
    PHP Code:
    <?php
    include("config.inc.php");
    // initialization
    $result_final "";
    $counter 0;
    // List of our known photo types
    $known_photo_types = array( 
         
    'image/pjpeg' => 'jpg',
         
    'image/jpeg' => 'jpg',
         
    'image/gif' => 'gif',
         
    'image/bmp' => 'bmp',
         
    'image/x-png' => 'png'
         
    );
     
    // GD Function List
    $gd_function_suffix = array( 
         
    'image/pjpeg' => 'JPEG',
         
    'image/jpeg' => 'JPEG',
         
    'image/gif' => 'GIF',
         
    'image/bmp' => 'WBMP',
         
    'image/x-png' => 'PNG'
         
    );
    // Fetch the photo array sent by preupload.php
    $photos_uploaded $_FILES['photo_filename'];
    // Fetch the photo caption array
    $photo_caption $_POST['photo_caption'];
    while( 
    $counter <= count($photos_uploaded) )
    {
    if(
    $photos_uploaded['size'][$counter] > 0)
    {
    if(!
    array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
    {
        
    $result_final .= "File ".($counter+1)." is not a photo<br />";
    }
    else
    {
        
    mysql_query"INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
        
    $new_id mysql_insert_id();
        
    $filetype $photos_uploaded['type'][$counter];
        
    $extention $known_photo_types[$filetype];
        
    $filename $new_id.".".$extention;
        
    mysql_query"UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
        
    // Store the orignal file
        
    copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);
        
    // Let's get the Thumbnail size
        
    $size GetImageSize$images_dir."/".$filename );
        if(
    $size[0] > $size[1])
        {
         
    $thumbnail_width 200;
         
    $thumbnail_height = (int)(200 $size[1] / $size[0]);
        }
        else
        {
         
    $thumbnail_width = (int)(200 $size[0] / $size[1]);
         
    $thumbnail_height 200;
        }
     
        
    // Build Thumbnail with GD 2.x.x
        
    $function_suffix $gd_function_suffix[$filetype]; 
        
    $function_to_read 'ImageCreateFrom' $function_suffix
        
    $function_to_write 'Image' $function_suffix
        
    // Read the source file 
        
    $source_handle $function_to_read($images_dir '/' $filename); 
     
        if (
    $source_handle) { 
         
    // Let's create a blank image for the thumbnail 
         
    $destination_handle ImageCreateTrueColor($thumbnail_width$thumbnail_height); 
         
    // Now we resize it 
         
    ImageCopyResampled($destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1]); 
        } 
        
    // Let's save the thumbnail 
        
    $function_to_write($destination_handle$images_dir '/tb_' $filename);
     
        
    $result_final .= "<img src='".$images_dir"/tb_".$filename."' /> File ".($counter+1)." Added<br />";
    }
    }
    $counter++;
    }
    // Print Result
    echo <<<__HTML_END
    <html>
    <head>
    <title>Photos uploaded</title>
    </head>
    <body>
    $result_final
    </body>
    </html>
    __HTML_END;
    ?>
    TIA for your help.

  2. #2
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since all GIF support was removed from the GD library in version 1.6, this
    function is not available if you are using that version of the GD library. Support
    is expected to return in a version subsequent to the rerelease of GIF support in
    the GD library in mid 2004.

    The following code snippet allows you to write more portable PHP applications
    by auto-detecting the type of GD support which is available. Replace the
    sequence header ("Content-type: image/gif"); imagegif ($im);
    http://il.php.net/manual/en/function.imagegif.php

    PHP Code:
    header("Content-type: image/gif");
    imagegif($image); 

    - Danny

  3. #3
    Non-Member
    Join Date
    Nov 2003
    Location
    here
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following code snippet allows you to write more portable PHP applications
    by auto-detecting the type of GD support which is available. Replace the
    sequence header ("Content-type: image/gif"); imagegif ($im);
    What does this mean? I too have been plagued by this problem.

  4. #4
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it looks like the current way to use the "imagegif()" function is by first
    adding the content type to the header or it wont work. - Atleast thats what I understood
    from this text.

    - Danny


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
  •