Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611

    funzione html.it per thumb quadrate

    raga non me ne volete male ma sto trovando difficoltà nell'implementare correttamente questa funzione...

    Codice PHP:
    function OutThumb($src$l){
      
    $size getimagesize($src);
      if( 
    $size[2] == ){$im = @imagecreatefromjpeg($src);}
      elseif( 
    $size[2] == ){$im = @imagecreatefromgif($src);}
      elseif( 
    $size[2] == ){$im = @imagecreatefrompng($src);}
      if( 
    $size[0]>$l or $size[1]>$l ){
        
    $centerX $size[0]/2;
        
    $centerY $size[1]/2;
        if( 
    $size[0] > $size[1] ){
          
    $luy 0;
          
    $lux $centerX-$centerY;
          
    $rdy $size[1];
          
    $rdx $size[1];
        }
        else{
          
    $lux 0;
          
    $luy $centerY-$centerX;
          
    $rdx $size[0];
          
    $rdy $size[0];
        }

        if( (
    GDVersion() == 2) AND ($size[2] != 1) ){
          
    $new imagecreatetruecolor($l$l);
          
    imagecopyresampled($new$im00$lux$luy$l$l$rdx$rdy);
        }
        else{
          
    $new imagecreate($l$l);
          
    imagecopyresized($new$im00$lux$luy$l$l$rdx$rdy);
        }
      }
      else{
        
    $new &= $im;
      }
      
    header('Content-Type: ' $size['mime']);
      if( 
    $size[2] == ){@imagejpeg($new$fileOut100);}
      elseif( 
    $size[2] == ){@imagegif($new$fileOut);}
      elseif( 
    $size[2] == ){@imagepng($new$fileOut);}
      @
    imagedestroy($im);
      @
    imagedestroy($new);

    trovata qui....

    http://php.html.it/articoli/leggi/93...i-gd-in-php/3/

    qualcuno per caso la utilizzata?

    grazie anticipatamente..

  2. #2
    che tipo di difficoltà incontri?

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611
    innanzitutto grazie per la disponibilità!

    io praticamente per uploadare le immagini sul server e inserirne il percorso su db, e per il ridimensionamento utilizzo il seguente codice....

    Codice PHP:
                if(isset($_FILES['foto']))
                    
    $foto $_FILES['foto'];
                else
                    
    $foto "";

                
    $numero count($foto['name']);
                
                
    $datafoto date('YmdHis');

                for(
    $i=1$i<$numero$i++){
                                
                    if (
    is_uploaded_file($foto['tmp_name'][$i])){
                        
    // Controllo che il file non superi i 1 MB
                        
    if ($foto['size'][$i] > 1024000) {
                            echo 
    "<script language='javascript'>alert('".$descri[33]."!! ".$descri[34]."'); history.back();</script>";
                            break;
                        }
                        
    // Ottengo le informazioni sull'immagine
                        
    list($width$height$type$attr) = getimagesize($foto['tmp_name'][$i]);
                        
                        
    // Controllo che il file sia in uno dei formati GIF, JPG o PNG
                        
    if (($type!=1) && ($type!=2) && ($type!=3)) {
                            echo 
    "<script language='javascript'>alert('".$descri[35]."!!\n".$descri[34]."'); history.back();</script>";
                            break;
                        }
                        
                        
    // Sposto il file nella cartella da me desiderata
                        
    $nomefile $datafoto.$foto['name'][$i];
                        if (!
    move_uploaded_file($foto['tmp_name'][$i], 'foto/big/'.$nomefile)) {
                            echo 
    "<script language='javascript'>alert('".$descri[36]."!!\n".$descri[34]."'); history.back();</script>";
                            break;
                        }
                        else {
                            
    // Ottengo le informazioni sull'immagine originale
                            
    list($width$height$type$attr) = getimagesize('foto/big/'.$datafoto.$foto['name'][$i]);
                            
    //chiamo la funzione calcola_miniatura
                            
    list($h_thumb,$w_thumb) = calcola_miniatura($width$height);
                            
                            
    // Creo la versione 120*90 dell'immagine (thumbnail) ???
                            
    $thumb imagecreatetruecolor($h_thumb$w_thumb);
                            if(
    $type == 1#gif
                                
    $source imagecreatefromgif('foto/big/'.$datafoto.$foto['name'][$i]);
                            elseif(
    $type == 2#jpg
                                
    $source imagecreatefromjpeg('foto/big/'.$datafoto.$foto['name'][$i]);
                            else 
    #png
                                
    $source imagecreatefrompng('foto/big/'.$datafoto.$foto['name'][$i]);
                                
                            
    imagecopyresized($thumb$source0000$h_thumb$w_thumb$width$height);
                            
                            
    // Salvo l'immagine ridimensionata
                            
    if($type == 1)
                                
    imagegif($thumb"foto/thumb/".$datafoto.$foto['name'][$i], 75);
                            elseif(
    $type == 2)
                                
    imagejpeg($thumb"foto/thumb/".$datafoto.$foto['name'][$i], 75);
                            else
                                
    imagepng($thumb"foto/thumb/".$datafoto.$foto['name'][$i], 75);
                
                                
    $sql "insert into foto(idannuncio, nomefoto) values ('$idcontrollo', '".$datafoto.$foto['name'][$i]."')";
                                
    $result mysql_query($sql) or die("errore query foto ".mysql_error());
                
                        }
                    }
                } 
    la funzione per calcolare la miniatura è questa...

    Codice PHP:

    $dim_thumb 
    120;
    function 
    calcola_miniatura_big($w$h) {
      global 
    $dim_thumb;
      
    $ret = array(0,0);
      
    $wt 0;
      
    $wh 0;
      if (
    $w $h) {
        
    $wt $dim_thumb;
        
    $ht $dim_thumb $h $w;
      }
      else {
        
    $ht $dim_thumb;
        
    $wt $dim_thumb $w $h;
      }
      
    $ret[0] = $wt;
      
    $ret[1] = $ht;
      return 
    $ret;


    ora vorrei integrare la funzione trovato su html.it sul mio procedimento e non so proprio come procedere e dove farla partire

    ho fatto delle prove ma niente da fare

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611
    up

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    1,611
    Originariamente inviato da bubu77
    che tipo di difficoltà incontri?
    devo lanciarla subito dopo aver acquisito l'immagine?

    subito dopo $_FILES['foto'] ?

    grazie anticipatamente...

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.