Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Php GD e classi

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2002
    Messaggi
    2,929

    Php GD e classi

    ciao a tutti!!
    una domandina per voi facile facile, ho una classe per le librerie gd come la devo usare?

    la classe è in un file php chiamato: gd_library_class.php e questo è il suo contenuto
    Codice PHP:
    <?
    class thumbnail 

        var 
    $img

        function 
    thumbnail($imgfile
        { 
            
    //detect image format 
            
    $this->img["format"]=ereg_replace(".*.(.*)$","\1",$imgfile); 
            
    $this->img["format"]=strtoupper($this->img["format"]); 
            if (
    $this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
                
    //JPEG 
                
    $this->img["format"]="JPEG"
                
    $this->img["src"] = ImageCreateFromJPEG ($imgfile); 
            } elseif (
    $this->img["format"]=="PNG") { 
                
    //PNG 
                
    $this->img["format"]="PNG"
                
    $this->img["src"] = ImageCreateFromPNG ($imgfile); 
            } elseif (
    $this->img["format"]=="GIF") { 
                
    //GIF 
                
    $this->img["format"]="GIF"
                
    $this->img["src"] = ImageCreateFromGIF ($imgfile); 
            } elseif (
    $this->img["format"]=="WBMP") { 
                
    //WBMP 
                
    $this->img["format"]="WBMP"
                
    $this->img["src"] = ImageCreateFromWBMP ($imgfile); 
            } else { 
                
    //DEFAULT 
                
    echo "Not Supported File"
                exit(); 
            } 
            @
    $this->img["lebar"] = imagesx($this->img["src"]); 
            @
    $this->img["tinggi"] = imagesy($this->img["src"]); 
            
    //default quality jpeg 
            
    $this->img["quality"]=75
        } 

        function 
    size_height($size=100
        { 
            
    //height 
            
    $this->img["tinggi_thumb"]=$size
            @
    $this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
        } 

        function 
    size_width($size=100
        { 
            
    //width 
            
    $this->img["lebar_thumb"]=$size
            @
    $this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
        } 

        function 
    size_auto($size=100
        { 
            
    //size 
            
    if ($this->img["lebar"]>=$this->img["tinggi"]) { 
                
    $this->img["lebar_thumb"]=$size
                @
    $this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
            } else { 
                
    $this->img["tinggi_thumb"]=$size
                @
    $this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
            } 
        } 

        function 
    jpeg_quality($quality=75
        { 
            
    //jpeg quality 
            
    $this->img["quality"]=$quality
        } 

        function 
    show() 
        { 
            
    //show thumb 
            
    @Header("Content-Type: image/".$this->img["format"]); 

            
    /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
            
    $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
                @
    imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

            if (
    $this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
                
    //JPEG 
                
    imageJPEG($this->img["des"],"",$this->img["quality"]); 
            } elseif (
    $this->img["format"]=="PNG") { 
                
    //PNG 
                
    imagePNG($this->img["des"]); 
            } elseif (
    $this->img["format"]=="GIF") { 
                
    //GIF 
                
    imageGIF($this->img["des"]); 
            } elseif (
    $this->img["format"]=="WBMP") { 
                
    //WBMP 
                
    imageWBMP($this->img["des"]); 
            } 
        } 

        function 
    save($save=""
        { 
            
    //save thumb 
            
    if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]); 
            
    /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
            
    $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
                @
    imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

            if (
    $this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
                
    //JPEG 
                
    imageJPEG($this->img["des"],"$save",$this->img["quality"]); 
            } elseif (
    $this->img["format"]=="PNG") { 
                
    //PNG 
                
    imagePNG($this->img["des"],"$save"); 
            } elseif (
    $this->img["format"]=="GIF") { 
                
    //GIF 
                
    imageGIF($this->img["des"],"$save"); 
            } elseif (
    $this->img["format"]=="WBMP") { 
                
    //WBMP 
                
    imageWBMP($this->img["des"],"$save"); 
            } 
        } 

    ?>
    grazie a tutti

  2. #2
    Utente di HTML.it L'avatar di Razorblade
    Registrato dal
    Feb 2002
    Messaggi
    1,308
    Ciao,
    sarebbe l'ideale trovassi la documentazione ufficiale di questa classe.
    Se non riesci o magari non esiste ti posso consigliare innanzitutto di istanziarla

    Codice PHP:
    $imgfile // nome immagine con percorso fisico
    $img = new thumbnail($imgfile); 
    a questo punto puoi richiamare i vari metodi in questo modo

    Codice PHP:
    $img->show(); 
    Chiaro?
    Ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2002
    Messaggi
    2,929
    Ciao scusami se rispondo solo adesso, ma ho avuto l'influenza...

    allora ho questa funzione:
    Codice PHP:
    function SaveProportionateImage($filename$quality$height$width){ 

            
    $dest_image imagecreatetruecolor$width ,$height); 

            
    imagecopyresampled($dest_image$this->src_image0000

                
    $width

                
    $height

                
    $this->src_width

                
    $this->src_height); 

            
    imagejpeg($dest_image$filename.'.jpg'$quality); 

            
    imagedestroy($dest_image); 

        } 
    e poi ho un file (che funziona alla grande) con il quale faccio l'upload
    solo che oltre a caricare l'immagine cosi com'è io vorrei creare una miniatura, quindi dovrei richiamare la funzione per fagli salvare il miniatura dentro un'altra cartella

    ma dove dovrei richiamarla questa funzione?
    Codice PHP:
    SaveProportionateImage($filename$quality$height$width

    Codice PHP:

    $uppath 
    "../../autogru";
    $dimlim true;
    $formatolim true;
    $size 11102400;
    $larg800;
    $alte600;
    $tipi = Array(
        
    'image/pjpeg'
        
    'image/jpeg'
        
    'image/gif'
        
    'image/png'
        
    'image/bmp'
        
    //'application/pdf'
    );
    $errori = Array(
        
    "Nessun file selezionato per l'upload",
        
    "Il File esiste gia",
        
    "Il file è troppo grande! Non deve superare i {$size} byte",
        
    "Il formato è piu grande del limite {$larg} x {$alte}",
        
    "Il file scelto non è valido [".implode(', '$tipi)."]"
        
    "Impossibile spostare il file sulla cartella {$uppath}, verifica CHMOD"
    );
    $x = array();  // Creo l'array
    $logs '';
    foreach(
    $_FILES as $k => $v) {
        if(isset(
    $v['name']) && $v['name'] !== '') {
            
    $moveto $uppath.'/'.$v['name'];
            if(
    file_exists($moveto))
                
    //$logs .= $errori[1].'
    ';
                rename($v['
    name'], $v['name']+$v['size']);
            else {
                $errorfile = false;
                if($dimlim && intval($v['
    size']) > $size) {
                    $logs .=  $errori[2].'
    ';
                    $errorfile = true;
                }
                if($formatolim) {
                    $s = @getimagesize($v['
    tmp_name']);
                    if($s[0]>$larg || $s[1]>$alte) {
                        $logs .=  $errori[3].'
    ';
                        $errorfile = true;
                    }
                }
                if(!in_array($v['
    type'], $tipi)) {
                    $logs .=  $errori[4].'
    ';
                    $errorfile = true;
                }
                if($errorfile === false && @move_uploaded_file($v['
    tmp_name'], $moveto)) {
                    $logs .= '
    File '.$v['name'].' caricato con successo!!
    ';
                    
                }else
                    $logs .= $errori[5];
            }
        }
        else
            array_push($x, array("FATTO", "FATTO"));


    grazie, spero tu possa aiutarmi.

  4. #4
    Utente di HTML.it L'avatar di Razorblade
    Registrato dal
    Feb 2002
    Messaggi
    1,308
    Ciao,
    ma SaveProportionateImage è il metodo di quale classe?
    Al suo interno c'è $this->src_image, quindi non è una funzione a se stante ma nella classe che avevi postato non era presente come metodo.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.