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

    Impostazioni libreria GD2

    Ciao, ho una galleria fotografica, che fino ad un po di tempo fa funzionava, ora cambiando hosting, nella generazione delle miniature mi da un effetto grafico finale che fa un po schifo a livello di qualità.. da cosa può dipendere?

    Link alla galleria d'esempio
    http://81.75.250.45/PROVE/Album/inde...INIATURE/PROVA

    Questo è il codice che mi genera le miniature
    codice:
    <?php 
    
    if(isset($_GET[calcola]))
    {
    	$gd2=checkgd();
    	$pics=directory($folder_browser,"jpg,JPG,JPEG,jpeg,png,PNG");
    	$pics=ditchtn($pics,"tn_");
    }
    
    if ($pics[0]!=""){
    	foreach ($pics as $p)
    	{
    		createthumb($folder_browser."/".$p,$folder_browser."/tn_".$p,$h_dimension_thumb,$w_dimension_thumb);
    	}
    }
    /*
    	Function checkgd()
    	checks the version of gd, and returns "yes" when it's higher than 2
    */
    function checkgd(){
    	$gd2="";
    	ob_start();
    	phpinfo(8);
    	$phpinfo=ob_get_contents();
    	ob_end_clean();
    	$phpinfo=strip_tags($phpinfo);
    	$phpinfo=stristr($phpinfo,"gd version");
    	$phpinfo=stristr($phpinfo,"version");
    	$end=strpos($phpinfo," ");
    	$phpinfo=substr($phpinfo,0,$end);
    	$phpinfo=substr($phpinfo,7);
    	if (preg_match("/2./",$phpinfo)){$gd2="yes";}
    	return $gd2;
    }
    
    /*
    	Function ditchtn($arr,$thumbname)
    	filters out thumbnails
    */
    function ditchtn($arr,$thumbname){
    	foreach ($arr as $item){
    		if (!preg_match("/^".$thumbname."/",$item))
    		{
    			$tmparr[]=$item;
    		}
    	}
    	return $tmparr;
    }
    
    /*
    	Function createthumb($name,$filename,$new_w,$new_h)
    	creates a resized image
    	variables:
    	$name		Original filename
    	$filename	Filename of the resized image
    	$new_w		width of resized image
    	$new_h		height of resized image
    */	
    function createthumb($name,$filename,$new_w,$new_h){
    	set_time_limit(20*60);
    	global $gd2;
    	global $w_sfondo;
    	global $h_sfondo;
    	
    	
    	$system=explode(".",$name);
    	if (preg_match("/jpg|jpeg|JPG|JPEG/",$system[1])){$src_img=imagecreatefromjpeg($name);}
    	else if (preg_match("/png|PNG/",$system[1])){$src_img=imagecreatefrompng($name);}
    	else return false;
    	
    	$old_x = imageSX($src_img) or die ("Si sono verificati degli errori nella generazione con ".$src_img);
    	$old_y = imageSY($src_img) or die ("Si sono verificati degli errori nella generazione con ".$src_img);
    	if ($old_x > $old_y) {
    		$thumb_w=$new_w;
    		$thumb_h=$old_y*($new_h/$old_x);
    	}
    	if ($old_x < $old_y) {
    		$thumb_w=$old_x*($new_w/$old_y);
    		$thumb_h=$new_h;
    	}
    	if ($old_x == $old_y) {
    		$thumb_w=$new_w;
    		$thumb_h=$new_h;
    	}
    	if ($gd2=="")
    	{
    		$TW = ($w_sfondo - $thumb_w)/2;
    		$TH = ($h_sfondo - $thumb_h)/2;
    		$BW = 0;
    		$BH = 0;
    			
    		$dst_img=ImageCreate($thumb_w,$thumb_h);
    		imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    
    		$sfn_img = ImageCreate($w_sfondo,$h_sfondo);
    		$white = imagecolorallocate ($sfn_img, 255, 255, 255);
    		imagefill($sfn_img, 0, 0, $white);
    		imagecopymerge($sfn_img,$dst_img,$TW,$TH,$HW,$BH,$thumb_w,$thumb_h,100);			
    						
    	}
    	else
    	{
    		$dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
    		imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    		
    		/*immagine di sfondo*/
    		
    		$sfn_img = ImageCreate($w_sfondo,$h_sfondo);
    		$white = imagecolorallocate ($sfn_img, 255, 255, 255);
    		imagefill($sfn_img, 0, 0, $white);
    		imagecopymerge($sfn_img,$dst_img,$TW,$TH,$HW,$BH,$thumb_w,$thumb_h,100);
    		
    	}
    
    
    	if (preg_match("/png/",$system[1]))
    	{
    		imagepng($sfn_img,$filename); 
    	} 
    	else 
    	{
    		imagejpeg($sfn_img,$filename);
    	}
    	imagedestroy($sfn_img);
    	imagedestroy($dst_img); 
    	imagedestroy($src_img);
    	
    	return true;
    }
    
    /*
            Function directory($directory,$filters)
            reads the content of $directory, takes the files that apply to $filter 
    		and returns an array of the filenames.
            You can specify which files to read, for example
            $files = directory(".","jpg,gif");
                    gets all jpg and gif files in this directory.
            $files = directory(".","all");
                    gets all files.
    */
    function directory($dir,$filters){
    	$handle=opendir($dir);
    	$files=array();
    	if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
    	if ($filters != "all"){
    		$filters=explode(",",$filters);
    		
    		while (($file = readdir($handle))!==false) 
    		{
    
    			for ($f=0;$f<sizeof($filters);$f++):
    			{	
    				$system=explode(".",$file);
    				if ($system[1] == $filters[$f])
    				{
    					$files[] = $file;
    				}
    				
    
    			}
    			
    			endfor;
    
    		}
    	}
    	closedir($handle);
    	return $files;
    }
    ?>
    Secondo voi da cosa può dipendere?
    Come posso risolvere?
    Incredibile, quanto a volte ci si impegola in qualcosa che sembra impossibile..
    e poi si scopre che quel che si dava per scontato, perchè banale, ne fosse la soluzione..

  2. #2
    Nessunao che ha idea di come settare le GD2??
    Incredibile, quanto a volte ci si impegola in qualcosa che sembra impossibile..
    e poi si scopre che quel che si dava per scontato, perchè banale, ne fosse la soluzione..

  3. #3
    Se a qualcuno può interessare, ho risolto sostituendo la funzione imagecreate con imagecreatetruecolor ed ora tutto è ok!
    Ciao!!
    Incredibile, quanto a volte ci si impegola in qualcosa che sembra impossibile..
    e poi si scopre che quel che si dava per scontato, perchè banale, ne fosse la soluzione..

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.