<?php
function makeimage($filename,$image_type,$newfilename,$path,$longside) {
ini_set('memory_limit', '256M');
$factor = 0;
$image_type1 = strtolower(strstr($image_type, '.'));
switch($image_type1) {
case '.jpg':
$source = imagecreatefromjpeg($filename);
break;
case '.png':
$source = imagecreatefrompng($filename);
break;
case '.gif':
$source = imagecreatefromgif($filename);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
$fullpath = $path . $newfilename . $image_type;
$thumb_fullpath = $path . 'thumb/thumb_' . $newfilename . $image_type;
list($width, $height) = getimagesize($filename);
if (($width > $longside) || ($height > $longside)){
if ($width > $height) {
$factor = $width / $longside;
$newheight = $height / $factor;
$newwidth = $longside;
}
else {
$factor = $height / $longside;
$newwidth = $width / $factor;
$newheight = $longside;}
}
else{
$newheight = $height;
$newwidth = $width;
}
$thumb_newheight = 114;
if ($height > $width){
$thumb_newwidth = 75;}
else {
$thumb_newwidth = 152;
}
$newpic = imagecreatetruecolor($newwidth, $newheight);
$thumb_newpic = imagecreatetruecolor($thumb_newwidth, $thumb_newheight);
ImageCopyResampled($newpic, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
ImageCopyResampled($thumb_newpic, $source, 0, 0, 0, 0, $thumb_newwidth, $thumb_newheight, $width, $height);
imagejpeg($newpic, $fullpath, 90);
imagejpeg($thumb_newpic, $thumb_fullpath, 90);
return $fullpath;
}
?>