Basically, this will add a logo to the bottom right corner of the image leaving a 10-pixel gap between the logo and the edge of the image.
<?php
define ('PADDING', 10);
$size[0] = getimagesize ('./myjpg.jpg');
$size[1] = getimagesize ('./logo.jpg');
$orig = imagecreatefromjpeg ('./myjpg.jpg');
$mark = imagecreatefromjpeg ('./logo.jpg');
imagecopyresampled ($orig, $mark, $size[0][0] - size[1][0] - PADDING, $size[0][1] - $size[1][1] - PADDING, 0, 0, $size[1][0], $size[1][1], $size[1][0], $size[1][1]);
?>
Once you've uploaded the image, you need to use variables instead of a straight file name to edit the image.
I would suggest doing it at upload because GD can be quite slow and server-intenseive doing it the other way. My suggestion would be to generate two files when the upload a file:
upload_x_original.jpg
upload_x_thumb.jpg