Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di MM88
    Registrato dal
    Jun 2003
    Messaggi
    567

    Crop di immagini in una cartella

    Ciao a tutti, vorrei creare una routine per leggere tutte le immagini contenute in una cartella, per poi visualizzarle tagliate (con dimensioni da me determinate).

    La funzione imagecopy fa al caso mio?

    ho trovato questa routine sul manuale, ma non so se sia corretta e come utilizzarla:

    codice:
    <?php
    $w=$_GET['w'];
    $h=isset($_GET['h'])?$_GET['h']:$w;    // h est facultatif, =w par défaut
    $x=isset($_GET['x'])?$_GET['x']:0;    // x est facultatif, 0 par défaut
    $y=isset($_GET['y'])?$_GET['y']:0;    // y est facultatif, 0 par défaut
    $filename=$_GET['src'];
    header('Content-type: image/jpg');
    header('Content-Disposition: attachment; filename='.$src);
    $image = imagecreatefromjpeg($filename); 
    $crop = imagecreatetruecolor($w,$h);
    imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
    imagejpeg($crop);
    ?>

    grazie

  2. #2
    Utente di HTML.it L'avatar di MM88
    Registrato dal
    Jun 2003
    Messaggi
    567
    Ho trovato questo script:

    codice:
    $nw=50; //The Width Of The Thumbnails
    $nh=50; //The Height Of The Thumbnails
    
    $ipath = "pics/"; //Path To Place Where Images Are Uploaded. No Trailing Slash
    $tpath = "pics/thumbnails";//Path To Place Where Thumbnails Are Uploaded. No Trailing Slash
    
    $img_name = $ipath."img1.jpg";
    
    $dimensions = GetImageSize($img);
    
    //$thname = "$tpath/$img_name";
    $thname = "$img_name";
    
    $w=$dimensions[0];
    $h=$dimensions[1];
    
    $img2 = ImageCreateFromJpeg($img);
    $thumb=ImageCreateTrueColor($nw,$nh);
    	
    $wm = $w/$nw;
    $hm = $h/$nh;
    	
    $h_height = $nh/2;
    $w_height = $nw/2;
    	
    if($w > $h){
    	
    	$adjusted_width = $w / $hm;
    	$half_width = $adjusted_width / 2;
    	$int_width = $half_width - $w_height;
    	
    	ImageCopyResampled($thumb,$img2,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); 
    	ImageJPEG($thumb,$thname,95); 
    	
    }elseif(($w < $h) || ($w == $h)){
    	
    	$adjusted_height = $h / $wm;
    	$half_height = $adjusted_height / 2;
    	$int_height = $half_height - $h_height;
    	
    	touch($thname);
    	ImageCopyResampled($thumb,$img2,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); 
    	ImageJPEG($thumb,$thname,95); 
    	
    }else{
    	ImageCopyResampled($thumb,$img2,0,0,0,0,$nw,$nh,$w,$h); 	
    	ImageJPEG($thumb,$thname,95); 
    }
    
    imagedestroy($img2);
    ?>

    Utilizzando un:

    echo "<img src=\"$thumb\">";

    Non ottengo l'output dell'immagine. La cartella "thumbnails" sul server è vuota e, verificando la variabile $thumb, mi restituisce un "Resource id #6".


    Come faccio a visualizzare l'immagine croppata?

    grazie

  3. #3
    Utente di HTML.it L'avatar di MM88
    Registrato dal
    Jun 2003
    Messaggi
    567
    UP

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.