Ver Mensaje Individual
  #8 (permalink)  
Antiguo 09/05/2010, 07:10
wani1985
 
Fecha de Ingreso: abril-2010
Mensajes: 62
Antigüedad: 14 años
Puntos: 0
Respuesta: Reescalar imagen

Código PHP:
function fun_resizejpg($imgsrc,$imgnew,$newx,$newy,$quality){  
if( 
file_exists($imgsrc) )     {  
list(
$srcx,$srcy,$ext) = getimagesize($imgsrc);       
switch( 
$ext)       {    
case 
:     
$old imagecreatefromgif($imgsrc);                     
$img imagecreate($srcx,$srcy);
imagecolorallocate($img255255255);                             
imagecopy($img,$old,0,0,0,0,$srcx,$srcy); 
break;               
case 
:     
$img imagecreatefromjpeg($imgsrc); 
break;                           
case 
:     
$img imagecreatefrompng($imgsrc);
 break;    
case 
6:     
$img imagecreatefromwbmp($imgsrc);  
break;               
default:
print_r(getimagesize($imgsrc)); 
return 
false;       }                
$tamx=$srcx;         
$tamy=$srcy;        
if(
$srcx>$newx)
$pv=($srcx>$srcy)?$srcx/$newx:$srcy/$newy;        
elseif(
$srcy>$newy)
$pv=($srcy>$srcx)?$srcy/$newy:$srcx/$newx;        
if(isset(
$pv)){    
$srcx=ceil($srcx/$pv);     
$srcy=ceil($srcy/$pv);     }               
$new imagecreatetruecolor ($srcx$srcy);             
imagecopyresampled ($new$img0000$srcx$srcy$tamx$tamy);                     
imagejpeg($new,(substr($imgnew,0,strrpos($imgnew,"."))).".jpg",$quality);        
imagedestroy($img);              
return 
true;    

else 
return 
false;
}


$imgsrc$imagen//url de la imagen a escalar
$imgnew$imagen//url de la imagen escalada
$ancho=getimagesize($imgsrc);
$factor=400/$ancho[0]; //las escala a 400px de ancho conservando las proporciones
$newx=$ancho[0]*$factor;
$newy=$ancho[1]*$factor
$quality=80
fun_resizejpg($imgsrc,$imgnew,$newx,$newy,$quality); 
simplemente le paso la url. Tiene que haber alguna forma de reescalar a nivel de mostrar en la web sin modificar la imagen del servidorm eso seria genial