I need to create an image on the fly where one large image covers a small image. The large image is a mask which makes the underlying image visible. Here is a quick sketch of what I'm trying to accomplish: http://i46.tinypic.com/2zidnjt.png. It's important that Y lies beneath X.
I have created to code for this and it works, but I was wondering how I can make the code more efficient. This is what I have:
// Create a blank image with the underlying image correctly positioned $blank = imagecreatetruecolor(403, 403); $profile = imagecreatefromjpeg('img.jpg'); $w = imagesx($profile); $h = imagesy($profile); imagecopy($blank, $profile, 0, 140, 0, 0, $w, $h); imagejpeg($blank, 'tmp.jpg', 100); // Frame overlay $frame = imagecreatefrompng('frame.png'); $photo = imagecreatefromjpeg('tmp.jpg'); imagecopy($photo, $frame, 0, 0, 0, 0, 403, 403); imagejpeg($photo, 'output.jpg', 100); // Garbage collection unlink('tmp.jpg'); imagedestroy($blank); imagedestroy($profile); imagedestroy($frame); imagedestroy($photo);
I just think that creating 2 different images is just overkill, but I just can't find a better solution.