$top = $_POST['top'];
    $left = $_POST['left'];
    $target = $_POST['add'];
    $tempaddress = explode("/", $target);
    $tempaddress1 = end($tempaddress);
    $u_ID_avatar1 = explode('_', $tempaddress1);
    $u_ID_avatar = $u_ID_avatar1[0];
    $tumbname = $tempaddress1;
    $picname = str_replace('tumb', '', $tumbname);
    $targettumbdir = str_replace($tempaddress1, '', $target);
    $targettumb = $targettumbdir . $tumbname;
    $filename = $targettumbdir . $picname;
    $imageCrop = new ImageCrop();
    if ($imageCrop->openImage($filename)) {
        $imageCrop->crop($left, $top);
        $imageCrop->save($targettumb, $targettumbdir, $tumbname, $u_ID_avatar);
    }
}
class ImageCrop
{
    private $srcImage, $dstImage;
    private $width, $height;
    public function openImage($filename)
    {
        if (!file_exists($filename)) {
            return false;
        }
        $original = getimagesize($filename);
        switch ($original['mime']) {
            case 'image/jpeg':
                $this->srcImage = imagecreatefromjpeg($filename);