<?php
$width = 100;
$height = 100;
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;
}
imagecopyresampled($tempImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight);
imagecopyresampled($newImage, $tempImage, 0, 0, $x, $y, $width, $height, $width, $height); imagejpeg($newImage, "thumbnails/example.jpg");
PD9waHAKJHdpZHRoID0gMTAwOwokaGVpZ2h0ID0gMTAwOwokaW1nID0gaW1hZ2VjcmVhdGVmcm9tanBlZygiZXhhbXBsZS5qcGciKTsKCiAgICAkaW1hZ2VXaWR0aCA9aW1hZ2VzeCgkaW1nKTsKICAgICRpbWFnZUhlaWdodCA9IGltYWdlc3koJGltZyk7CiAgICBpZigkaW1hZ2VXaWR0aD4kaW1hZ2VIZWlnaHQpewogICAgCSRuZXdIZWlnaHQ9JGhlaWdodDsKICAgIAkkbmV3V2lkdGggPSBmbG9vcigkaW1hZ2VXaWR0aCooJGhlaWdodC8kaW1hZ2VIZWlnaHQpKTsKICAgIAkkeCA9IGZsb29yKCRuZXdXaWR0aC8yLSR3aWR0aC8yKTsKICAgIAkkeSA9IDA7CiAgICB9CiAgICBlbHNlaWYoJGltYWdlV2lkdGg8JGltYWdlSGVpZ2h0KXsKICAgIAkkbmV3V2lkdGggPSAkd2lkdGg7CiAgICAJJG5ld0hlaWdodCA9IGZsb29yKCRpbWFnZUhlaWdodCooJHdpZHRoLyRpbWFnZVdpZHRoKSk7CiAgICAJJHk9Zmxvb3IoJG5ld0hlaWdodC8yLSRoZWlnaHQvMik7CiAgICAJJHggPSAwOwogICAgfQogICAgJHRlbXBJbWFnZSA9IGltYWdlY3JlYXRldHJ1ZWNvbG9yKCRuZXdXaWR0aCwgJG5ld0hlaWdodCk7CiAgICBpbW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