<?php

function imageResize($maxWidth$maxHeight$fileFrom$fileTo) {
    
$img false;
    if (
is_file($fileFrom)) {
        
$img imagecreatefromstring(file_get_contents($fileFrom));
    }

    if(
$img) {
        
$width ImageSX($img);
        
$height ImageSY($img);
        
$maxWidth = ($maxHeight=='*'?1000000:$maxHeight);
        
$maxHeight = ($maxHeight=='*'?1000000:$maxHeight);

        if (
$width $maxWidth || $height $maxHeight) {
            
$ratioX $width/$maxWidth;
            
$ratioY $height/$maxHeight;
            
$ratio = ($ratioX $ratioY)?$ratioX:$ratioY;

            
$newWidth $width $ratio;
            
$newHeight $height $ratio;
            
$newImage=ImageCreateTrueColor($newWidth$newHeight);
            
ImageCopyResampled ($newImage,
                                
$img0000,
                                
$newWidth,
                                
$newHeight,
                                
$width,
                                
$height);
            
ImageJPEG($newImage$fileTo80);
        } else {
            
ImageJPEG($img$fileTo80);
        }
        return 
true;
    } else {
        return 
false;
    }
}

?>