Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Crop rettangolare invece che quadrato

    Ciao a tutti!
    Attualmente uso per la creazione delle thumbs una funziona che mi crea delle thumb quadrate eseguendo un crop.
    Ora io vorrei far sì che il crop venga eseguito con un rapporto di 4:3, ovvero vorrei un'immagine rettangolare come risultato e non quadrata...

    Qualcuno saprebbe dirmi come fare?

    Posto il codice della funzione che genera thumbs quadrate:

    Codice PHP:

    function create_thumb($l$fileOut$src){
      global 
    $result;
      
    $type ".jpg";
        
    $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];
        }
          
    $new imagecreatetruecolor($l$l);
          
    imagecopyresampled($new$im00$lux$luy$l$l$rdx$rdy);
      }
      else{
        
    $new &= $im;
      }
      if( 
    $size[2] == ){@imagejpeg($new$fileOut."$type"78);}
      elseif( 
    $size[2] == ){@imagegif($new$fileOut);}
      elseif( 
    $size[2] == ){@imagepng($new$fileOut);}
      
    $result $fileOut;


  2. #2
    Mi rispondo da solo. Ho trovato questo script che esegue un crop secondo le dimensioni specificate
    Codice PHP:
    function create_thumb($nw$nh$source$stype$dest) {
        
    $size getimagesize($source);
        
    $w $size[0];
        
    $h $size[1];
        switch(
    $stype) {
            case 
    'gif':
            
    $simg imagecreatefromgif($source);
            break;
            case 
    'jpg':
            
    $simg imagecreatefromjpeg($source);
            break;
            case 
    'png':
            
    $simg imagecreatefrompng($source);
            break;
        }
        
    $dimg imagecreatetruecolor($nw$nh);
        
    $wm $w/$nw;
        
    $hm $h/$nh;
        
    $h_height $nh/2;
        
    $w_height $nw/2;
        if(
    $wm$hm) {
            
    $adjusted_width $w $hm;
            
    $half_width $adjusted_width 2;
            
    $int_width $half_width $w_height;
            
    imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
        } elseif((
    $wm <$hm) || ($w == $h)) {
            
    $adjusted_height $h $wm;
            
    $half_height $adjusted_height 2;
            
    $int_height $half_height $h_height;
            
    imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
        } else {
            
    imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
        }
        
    imagejpeg($dimg,$dest,78);


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 © 2024 vBulletin Solutions, Inc. All rights reserved.