$new_height = $thumbWidth;#floor( $height * ( $thumbWidth / $width ) );
sets your height to equal your width, but if you remove $thumbWidth; of $new_height = $thumbWidth; and replace it with the section that's commented out
floor( $height * ( $thumbWidth / $width ) );
You should get what you want.
You might have to change the dimensions of the displayed thumb nail to make it square and uniform again.