0

I Have A Background Image Now I want PHP to Put Another Image On Top Of It (The Other Image Is Stored in A Variable) Example variable $x & My Background Image Is Also A Variable $back Example ../img/back.jpg Now i wish to Add The $x On The Left side of The Background How May I Achieve this? Like In This Pic There is The Green Part with a Shadow Image How Can I replace that PART with another Picture using PHP? (https://i.stack.imgur.com/IjK0o.jpg) What i Have so Far

<?php
copy("https://graph.facebook.com/FACEBOOKID/picture?width=99&height=99", "picture.jpg");
$x =  "picture.jpg";
copy("https://i.stack.imgur.com/IjK0o.jpg","bg.jpg");
$back = "bg.jpg";
?>
  • See `imagecopy()` http://php.net/manual/en/function.imagecopy.php and all the other copy functions. – KIKO Software May 18 '17 at 07:19
  • Possible duplicate of [How do I position one image on top of another in HTML?](http://stackoverflow.com/questions/48474/how-do-i-position-one-image-on-top-of-another-in-html) – Andreas May 18 '17 at 07:21
  • @Andreas I don't think it's a duplicate. The OP want the output to be an image, not HTML. – Arnold Daniels May 18 '17 at 07:27

1 Answers1

0

Combining images is part of image processing. You can use the gd library directly. However I recommend using an OO image processing library like intervention image, which is easier to write and understand.

// open the background image file
$img = Image::make('bg.jpg');

// Add the facebook image
$img->insert('picture.jpg');

// Save the image as a new file
$img->save('newpicture.jpg');

Read the documentation about the insert method to understand how to position the facebook image.

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82