$newWidth = $w1 + $w2;
$newHeight = $h1 + $h2;
$newImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newImage, $image1, 0, 0, 0, 0, $w1, $h1, $w1, $h1);
imagecopyresampled($newImage, $image2, $w1, 0, 0, 0, $w2, $h2, $w2, $h2);
Now i did just code this in stack overflows editor and it is untested, but that should use all native libraries and probably be the fastest. Just copies and resamples the image1 into the first half (width wise) and then copies the second image into the second half (width wise), if you wanted to do it by stacking on height, it would just be changing where the dest_h is. Here is some info... http://php.net/manual/en/function.imagecopyresampled.php
oh BTW, that was for saving an image. That is what i am assuming your doing. Else the answer about stacking 2 images next to eachother with tags would be the fastest.
As far as the resulting image, remember. If they are laid horizontally, then the width would be $w1 + $w2
and the height would be math.max($h1, $h2)
and opposite if the images are stacked vertically