<?php
$width = 100;
$height = 100;
$img = imagecreatefromjpeg("example.jpg");

    $imageWidth =imagesx($img);
    $imageHeight = imagesy($img);
    if($imageWidth>$imageHeight){
    	$newHeight=$height;
    	$newWidth = floor($imageWidth*($height/$imageHeight));
    	$x = floor($newWidth/2-$width/2);
    	$y = 0;
    }
    elseif($imageWidth<$imageHeight){
    	$newWidth = $width;
    	$newHeight = floor($imageHeight*($width/$imageWidth));
    	$y=floor($newHeight/2-$height/2);
    	$x = 0;
    }
    $tempImage = imagecreatetruecolor($newWidth, $newHeight);
    imagecopyresampled($tempImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight);

    $newImage = imagecreatetruecolor($width, $height);
    imagecopyresampled($newImage, $tempImage, 0, 0, $x, $y, $width, $height, $width, $height);
    imagejpeg($newImage, "thumbnails/example.jpg");