图片上传脚本 - 如何调整大小

I'm new to programming and require some help regarding the below issue.

I have the below script that I guess controls the upload of the image.
Is there any easy way to add a autoresizer of the image to 1024x768?

public function index()
{
    $validator = Validator::make(Input::all(), [
        'image' => 'required|image|max:' . (1024 * 3),
    ]);

    if ($validator->fails()) {
        $messages = $validator->messages();
        echo json_encode([
            'return' => 'error',
            'message' => $messages->first('image')
        ]);
    } else {
        $originalName = Input::file('image')->getClientOriginalName();
        $extension = Input::file('image')->getClientOriginalExtension();
        $size = Input::file('image')->getSize();
        $type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
        $adult = Input::has('adult') ? Input::get('adult') : 0;
        $adult = ($adult != 1) ? 0 : 1;
        $status = (Settings::get('auto_approve_images') == 1) ? 'active' : 'pending';

        $image = new Image;
        $image->user_id = (Auth::check()) ? Auth::user()->id : 0;
        $image->file_name = $originalName;
        $image->file_extn = $extension;
        $image->file_size = $size;
        $image->status = $status;
        $image->type = $type;
        $image->adult = $adult;
        $image->ip = Net::getIP();
        $image->save();

        $imageFolder = floor($image->id / 1000) + 1;
        $imageFolder = md5($imageFolder);
        $imageFolder = substr($imageFolder, 1, 10);
        $imageFolder = trim($imageFolder);

        $image->folder = $imageFolder;
        $image->save();

        $destinationPath = public_path('uploads/' . $imageFolder);
        $fileName = $image->id . '.' . $extension;
        Input::file('image')->move($destinationPath, $fileName);

        $destinationPathThumb = public_path('thumb/' . $imageFolder);
        if (! File::isDirectory($destinationPathThumb)) {
            File::makeDirectory($destinationPathThumb, 0755, true);
        }
        $fileNameThumb = $image->id . '.' . $extension;
        $thumbWidth = (int) Settings::get('thumb_width');
        $thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
        $thumbHeight = (int) Settings::get('thumb_height');
        $thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
        Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);

        $fileNameMed = $image->id . '_md.' . $extension;
        $medWidth = 700;
        $medHeight = 600;
        Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);

        echo json_encode([
            'return' => 'success',
            'imageUid' => $image->id
        ]);
    }
    exit();
}

public function link()
{
    $validator = Validator::make(Input::all(), [
        'url' => 'required|url',
    ]);

    if ($validator->fails()) {
        return Redirect::back()->withErrors($validator);
    } else {
        $originalName = basename(Input::get('url'));
        $nameSplit = explode('.', $originalName);
        $extension = $nameSplit[count($nameSplit) - 1];

        if (! in_array($extension, ['jpeg', 'jpg', 'png', 'bmp', 'gif'])) {
            return Redirect::back()->withErrors($validator);
        }

        $type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
        $adult = Input::has('adult') ? Input::get('adult') : 0;
        $adult = ($adult != 1) ? 0 : 1;

        $image = new Image;
        $image->user_id = (Auth::check()) ? Auth::user()->id : 0;
        $image->file_name = $originalName;
        $image->file_extn = $extension;
        $image->status = 'active';
        $image->type = $type;
        $image->adult = $adult;
        $image->ip = Net::getIP();
        $image->save();

        $imageFolder = floor($image->id / 1000) + 1;
        $imageFolder = md5($imageFolder);
        $imageFolder = substr($imageFolder, 1, 10);
        $imageFolder = trim($imageFolder);

        $image->folder = $imageFolder;
        $image->save();

        $destinationPath = public_path('uploads/' . $imageFolder);
        $fileName = $image->id . '.' . $extension;
        File::copy(Input::get('url'), $destinationPath . '/' . $fileName);

        $size = File::size($destinationPath . '/' . $fileName);
        $image->file_size = $size;
        $image->save();

        $destinationPathThumb = public_path('thumb/' . $imageFolder);
        if (! File::isDirectory($destinationPathThumb)) {
            File::makeDirectory($destinationPathThumb, 0755, true);
        }
        $fileNameThumb = $image->id . '.' . $extension;
        $thumbWidth = (int) Settings::get('thumb_width');
        $thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
        $thumbHeight = (int) Settings::get('thumb_height');
        $thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
        Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);

        $fileNameMed = $image->id . '_md.' . $extension;
        $medWidth = 700;
        $medHeight = 600;
        Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);

        return Redirect::to('/upload/success?id=' . $image->id);
    }
}

public function success()
{
    if (! Input::has('id')) {
        return Redirect::to('/');
    }

    $imageIdArr = explode(',', Input::get('id'));
    $imageIdArr = array_where($imageIdArr, function($key, $value)
    {
        return is_numeric($value);
    });
    $imageIdArr = array_unique($imageIdArr);

    if (empty($imageIdArr)) {
        return Redirect::to('/');
    }

    $imagesInfo = Image::whereIn('id', $imageIdArr)->get();

    return View::make('upload.success', [
        'imagesInfo' => $imagesInfo,
    ]);
}

You can resize the image with some fileuploader in the client side, you also can use server side tools such as imagemagic with command like this:

`convert $original_path -resize '1024x768^' -gravity Center -crop '1024x768+0+0' $resized_path`;