[GD] getimagesize

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [GD] getimagesize

    Was für gibt den getimagesize zurück, falls das Bild bmp ist?
    1=>GIF
    2=>JPG
    3=>PNG
    4=>SWF

    BMPs dürfte es doch garnicht erkennen??
    Die Variable scheint aber nicht leer zu sein, aber fals ich sie per echo ausgebe, ist sie trotzdem leer.
    Hier der Hintergrund zur Frage:
    Falls eine BMP-Datei im Ordner vorhanden ist, dann gibts die Funktion (), die natürlich nicht definiert ist. Da es ja kein jpg oder png ist...
    PHP-Code:
    $new_size 500;
    $dirname "test";
    $dir opendir($dirname);
    $error 0;
    $acp 0;
    //auslesen des Verzeichnisses
    while($ofile readdir($dir))
        {
        if(
    $ofile != "." AND $ofile != "..")
                {
                    
    $filepath $dirname."/".$ofile;
                    
    $file getimagesize($filepath);
                    
                    
    $type $file[2];
                    
                    
    //Prüfung ob es sich um ein JPG, PNG oder GIF handelt
                    
    if(!empty($type))
                        {
                        
                        
    $function = array("1"=>"gif","2"=>array("load"=>"imagecreatefromjpeg","save"=>"imagejpeg"),"3"=>array("load"=>"imagecreatefrompng","save"=>"imagePng"));
                        
    $height $file[1];
                        
    $width $file[0];
                        
    //Ist das Bild Quer- oder Hochgestellt?
                        
    if(!empty($type))
                            {
                                if(
    $width >= $height)
                                    {
                                        
    $new_width $new_size;
                                        
    $new_height $height/($width/$new_width);
                                    }
                                else
                                    {
                                        
    $new_height $new_size;
                                        
    $new_width $width/($height/$new_height);
                                    }
                                
    $image $function[$type]["load"]($filepath);
                                
    $new_image imagecreatetruecolor($new_width$new_height);
                                
                                
    //erstellen des neuen Bildes
                                
    imagecopyresized($new_image$image0000$new_width$new_height$width $height); 
                                
                                
    //speichern
                                
    $function[$type]["save"]($new_image$ofile);
                                echo 
    "<font color='007320'>Die Datei <b>$ofile</b> wurde erfolgreich bearbeitet!</font></br>";
                                
    $acp++;
                            }
                        else
                            {
                                echo 
    "<font color='ff0000'>Die Datei <b>$ofile</b> ist eine Gif-Datei. Es können leider nur JPEG-. und PNG-Dateien bearbeitet werden. Der Gif Suppport ist ab GD1.6 leider nicht mehr verfügbar.</font></br>";
                                
    $error++;
                            }
                        }
                    else
                        {
                            echo 
    "<font color='ff0000'>Die Datei <b>$ofile</b> ist keine Bilddatei.</font></br>";
                            
    $error++;
                        }
                    }
        }
    echo 
    "</br>";
    if(
    $error != 0)
        {
            echo 
    "Es sind <b>$error Fehler</b> aufgetreten.</br>";
        }
    if(
    $acp != 0)
        {
            echo 
    "Es wurden <b>$acp Dateien</b> erfolgreich bearbeitet.</br>";
        }
    closedir($dir);
    ?> 
    Für Rechtschreibfehler übernehme ich keine Haftung!

  • #2
    vielleicht hilft dir das weiter.
    http://de.php.net/manual/de/function.getimagesize.php

    tightcode_nosp@m_hotmail
    14-Mar-2002 02:16

    If you are using a php version with the bug where GetImageSize returns
    nothing on certain types of jpeg images, the following replacement should
    solve the problem until you have upgraded.
    It accuratly duplicates the 1st and 2nd array element which are the ones I
    personally needed. I however added the 4th array element and a crude
    implementation of the 3rd since some people may need the functionality or
    find it usefull.
    I hopefully reformated the function to not be wordwrapped and it is worth
    noting that as it is written, it only will work on local files. Additional error
    checking may be wise.

    Code:
    function sgetimagesize($filename) {
      $ftype_array = array(".gif"=>"1",
                          ".jpg"=>"2",
                           ".jpeg"=>"2",
                            ".png"=>"3",
                            ".swf"=>"4",
                            ".psd"=>"5",
                            [b][color=red]".bmp"=>"6");[/color][/b]
       if (is_file($filename)) {
         $fd = @fopen($filename,"r");
           $image_string = fread($fd,filesize($filename));
           $im = ImageCreateFromString($image_string);
           $ftype = $ftype_array[get_file_ext($filename)];
           $gis[0] = ImageSX($im);
           $gis[1] = ImageSY($im);
           $gis[2] = ($ftype?$ftype:"0");
           $gis[3] = "width={$gis[0]} height={$gis[1]}";
           ImageDestroy($im);
           return $gis_array;
       }
       else { return false; }
    }
    Cheers,

    Tightcode
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar

    Lädt...
    X