/**
* @return Void
* @param Integer $cp_bigs
* @param String $picdir
* @param String $picname
* @param String/Boolean $copydir
* @desc Makes a resized and resampled scaled copy into specified directory. Returns false if fails.
*/
function make_res_copy($cp_bigs, $picdir, $picname, $copydir)
{
//check if file has a jpg (jpeg) extension
if(strstr(strtolower($picname), ".jpg") or strstr(strtolower($picname), ".jpeg"))
{
if(strstr(strtolower($picname), ".jpg") or strstr(strtolower($picname), ".jpeg"))
{
$im = ImageCreateFromJPEG($picdir . "/" . $picname);
}
//get the original image size
$size = getImageSize($picdir . "/" . $picname);
$dstX = 0;
$dstY = 0;
$srcX = 0;
$srcY = 0;
//decide wether picture is horizontally or vertically aligned
//-->ofcourse if the picture is rectangular all sides of the
//-->copy will be equal
if($size[0] < $size[1])
{
$ratio = $size[1]/$cp_bigs;
$dstW = $size[0] / $ratio;
$dstH = $cp_bigs;
}
elseif($size[0] == $size[1])
{
$dstW = $cp_bigs;
$dstH = $cp_bigs;
}
else
{
$ratio = $size[0]/$cp_bigs;
$dstW = $cp_bigs;
$dstH = $size[1] / $ratio;
}
$srcW = $size[0];
$srcH = $size[1];
$imdst = ImageCreateTruecolor($dstW, $dstH);
ImageCopyResampled($imdst, $im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
if($copydir)
ImageJPEG($imdst, $copydir . "/" . $picname);
else
ImageJPEG($imdst);
}
}
?>