Resizing files in php

is there a way to resize images (in terms of bytes) in php ?
I started this code, but i’m blocked on how to resize the image and save it

function resizePic($filename)
{
    define("BIG_SIZE",400);
    define("SMALL_SIZE",30);
    $imgInfo = getimagesize($filename);
    $imgWidth = $imgInfo[0];
    $imgHeight = $imgInfo[1];
    $scale = $imgHeight/$imgWidth;
    $bigWidth = $scale*DETAIL_SIZE;
    $smallWidth = $scale*LIST_SIZE;
     // how to save the new resized image?
}