Dynamic image using PHP
First of all don't save your temporary file as tmp.jpg, think about what happends if there are 2 requests for an image at the same time, the first tmp.jpg will be overwritten by the second one (very unlikely, but still possible and very hard to debug / reproduce bug)..

Second saving to the disk is expensive and useless, avoid it whenever possible.

Third why do you need the blank image? I think you should have the frame image and overlay the profile image on top of it.

Given this, I think the code should look like this:

// Create a blank image with the underlying image correctly positioned
$base = imagecreatefrompng('frame.png');
$profile = imagecreatefromjpeg('img.jpg');
$w = imagesx($profile);
$h = imagesy($profile);
imagecopy($base, $profile, 0, 140, 0, 0, $w, $h);

imagejpeg($base, 'output.jpg', 100);

// Garbage collection
imagedestroy($base);
imagedestroy($profile);


Unless I miss something this code should do exactly the same thing, but faster and safer.