function create_thumbnail($source,$destination,$thumb_width)
{
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
$x = 0;
$y = 0;
if($width > $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} else if ($height > $width)
{
$y = ceil(($height - $width) / 2);
$height = $width;
}
$new_image = imagecreatetruecolor($thumb_width,$thumb_width);
$extension = $this->get_image_extension($source);
if($extension == 'jpg' || $extension == 'jpeg')
{
$image = imagecreatefromjpeg($source);
}
if($extension == 'gif')
{
$image = imagecreatefromgif($source);
}
if($extension == 'png')
{
$image = imagecreatefrompng($source);
}
imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);
if($extension == 'jpg' || $extension = 'jpeg')
{
imagejpeg($new_image,$destination);
}
if($extension == 'gif')
{
imagegif($new_image,$destination);
}
if($extension == 'png')
{
imagepng($new_image,$destination);
}
}
function get_image_extension($name)
{
$name = strtolower($name);
$i = strpos($name,".");
if(!$i) { return ""; }
$l = strlen($name) - $i;
$extension = substr($name,$i+1,$l);
return $extension;
}
function resizeGalleryImage($source)
{
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
if($width > 400)
{
$this->create_thumbnail($source,$source,400);
}
}