I want to merge two images by gd library in php
first image is my local image which is in the same folder of my file
but i want to get the second image from somewhere else in internet
i mean , the second image is something like this : http://www.somewhere.com/pics/image.jpg
i try to merge but it doesnt work 🙁
this is my code:
source is my jpeg URL. it works when jpeg file is in the same folder !!
header('Content-Type: image/jpeg');
if ( isset( $_POST['source'] ) ){
$source = $_POST['source'];
$watermark = imagecreatefrompng( 'logo.png' );
$watermark_width = imagesx( $watermark );
$watermark_height = imagesy( $watermark );
$image = imagecreatetruecolor( $watermark_width, $watermark_height );
$image = imagecreatefromjpeg( $source );
$imagesize = getimagesize( $source );
$x = $imagesize[0] - $watermark_width - 10;
$y = $imagesize[1] - $watermark_height - 10;
imagecopymerge( $image, $watermark, $x, $y, 0, 0, $watermark_width, $watermark_height, 20 );
imagejpeg( $image );
}
Thank you.
There are a couple ways to solve this. You can use
curlto pull the remote image down to your local machine. Since you said your code works when the image is in the same folder, you should be all set then.