SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: gif images

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gif images

    Case 2 and 3 work but case 4 (gif) does not, as a result i cant upload .gif

    Can anyone see why?

    Code php:
    <?php
    function thumbnail($fileSrc,$fileDest,$thumb_width,$thumb_height)
    {
           list($width,$height,$type,$attr)=getimagesize($fileSrc);
           switch($type){ 
            case 2:
                $img=imagecreatefromjpeg($fileSrc);
                $fileDest=$fileDest;
                break;
            case 3:
                $img=imagecreatefrompng($fileSrc);
                $fileDest=$fileDest;
                break;
            case 4:
                $img=imagecreatefromgif($fileSrc);
                $fileDest=$fileDest;
                break;
    }
     
        if($thumb_height>$thumb_width){
         $scale=$thumb_height/$height;
    }else{
        $scale=$thumb_width/$width;
    }
     
    $thumb_width=$width*$scale;
    $thumb_height=$height*$scale;
    $thumb = imagecreatetruecolor($thumb_width,$thumb_height);
     
        imagecopyresampled($thumb,$img,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
     
        switch($type){
            case 2:
                imagejpeg($thumb,$fileDest);
                break;
            case 3:
                imagepng($thumb,$fileDest);
                break;
            case 4:
                imagegif($thumb,$fileDest);
                break;
        }
        return basename($fileDest);
    }
     
    ?>
    Last edited by stymiee; Nov 18, 2007 at 09:59. Reason: cleaned up code and used highlight tags

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because gif is 1, while 4 is swf?

    Code:
    1 IMAGETYPE_GIF 
    2 IMAGETYPE_JPEG 
    3 IMAGETYPE_PNG 
    4 IMAGETYPE_SWF 
    5 IMAGETYPE_PSD 
    6 IMAGETYPE_BMP 
    7 IMAGETYPE_TIFF_II (intel byte order) 
    8 IMAGETYPE_TIFF_MM (motorola byte order)  
    9 IMAGETYPE_JPC 
    10 IMAGETYPE_JP2 
    11 IMAGETYPE_JPX 
    12 IMAGETYPE_JB2 
    13 IMAGETYPE_SWC 
    14 IMAGETYPE_IFF 
    15 IMAGETYPE_WBMP 
    16 IMAGETYPE_XBM
    Use the constants to avoid confusion.
    Saul


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
  •