L'ho messa in una funzione stand-alone,

Codice PHP:
<?php

function getResized($w$h)
{
    
$maxWidth 450;
    
$maxHeight 300;
    
    
$originalW $w;
    
$originalH $h;
     
    if( 
$originalW <= $maxWidth && $originalH <= $maxHeight )
    {
        
$profileTHBWidth $originalW;
        
$profileTHBHeight $originalH;
    }
    else if( 
$originalW $maxWidth || $originalH $maxHeight )
    {
        if(
$originalW $maxWidth )
        {
            
$coeffW 1;
            print 
"COEFF W\n";
            do
            {
                print 
$coeffW."%\n";
                
$profileTHBWidth $originalW-(($originalW*$coeffW)/100);
                ++
$coeffW;
            } while( 
$profileTHBWidth $maxWidth );
            
            
$profileTHBHeight $originalH-(($originalH*$coeffW)/100);
            
            if( 
$profileTHBHeight $maxHeight )
            {
                print 
"COEFF H\n";
                
$coeffH $coeffW;
                do
                {
                    print 
$coeffH."%\n";
                    
$profileTHBHeight $originalH-(($originalH*$coeffH)/100);
                    
$profileTHBWidth $originalW-(($originalW*$coeffH)/100);
                    ++
$coeffH;
                } while( 
$profileTHBHeight $maxHeight );
            }
            else { 
/*va bene*/ }
        }
        else if( 
$originalH $maxHeight )
        {
            
$coeffH 1;
            do
            {
                
$profileTHBHeight $originalH-(($originalH*$coeffH)/100);
                
$profileTHBWidth $originalW-(($originalW*$coeffH)/100);
                ++
$coeffH;
            } while( 
$profileTHBHeight $maxHeight );
            
$profileTHBWidth $originalW-(($originalW*$coeffH)/100);
        }
    }
    return array(
$profileTHBWidth$profileTHBHeight);
}

print_r(getResized(600700));
?>