PHP overlays png on image

Hello, I have a wordpress plug-in that uploads an image from the users directory and places it in a sized box.
 The code for that:
<?php require_once('../../../../../../../../wp-blog-header.php');
	
	session_start();
	unset($_SESSION['upload_id']);
	unset($_SESSION['front_design']);
	$filename = $_FILES["uploadfile"]["name"];
	$ext = substr(strrchr($filename, "."), 1);
	//$randName = md5(rand() * time());
	//$randName = uniqid();
	$randName = time().uniqid();
	$filename = $randName . '.' . $ext; 
	$_SESSION['front_design'] = $randName;
	$_SESSION['upload_id'] = $filename;
	
									
	if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"],"../cs/uploadImage/" . $filename)){
	//image resize
	$ab_path= plugin_dir_path( __FILE__ ); 
	$img_path = wp_get_image_editor($ab_path.'/uploadImage/'.$filename);
	if (!is_wp_error( $img_path ) ) {
	$img_path->resize(220,220,true);
	$saved = $img_path->save();
	$getpos2=strpos($saved['path'],'/wp-content');
	
	$getstr2=substr($saved['path'],$getpos2);
	
	$resize_file_name=basename($getstr2);
				}
	echo $resize_file_name;
	
	}
	else{
		echo "error";
	}
?>

Open in new window

What I'd like to do is load a png image immediately after the users image is uploaded and place it directly on top of the users image. (like a mask) My mask image is in the directory root and will always be the same path. I haven't been able to write the code correctly, is there a function or snippet that I could insert to make that happen?
Thanks in advance for any help.
stoneycurtisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Please see: http://www.laprbass.com/RAY_image_watermark.php

<?php // RAY_image_watermark.php
error_reporting(E_ALL);

// LOCATION OF THE IMAGES (COULD COME IN FROM $_GET URL STRING)
$original = 'http://www.LAPRBass.com/RAY_add_watermark_source_image.png';
$h2o_mark = 'http://www.LAPRBass.com/RAY_add_watermark_watermark_image.png';

// READ THE IMAGE AND THE WATERMARK FILE
// MAN PAGE http://php.net/manual/en/function.imagecreatefrompng.php
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($h2o_mark);

// ADD WATERMARK USING LOCAL FUNCTION
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));

// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);

// A FUNCTION TO ADD THE LOGO WATERMARK
// SEE http://php.net/manual/en/function.imagealphablending.php#77085
function imagelogo (&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h)
{
    ImageAlphaBlending($dst_image,TRUE);
    ImageAlphaBlending($src_image,TRUE);
    ImageCopy($dst_image, $src_image, ($dst_w-$src_w), ($dst_h-$src_h), 0, 0, $src_w, $src_h);
}

Open in new window

0
stoneycurtisAuthor Commented:
Ray, thanks for answering so quickly,
That looks like the code I've been trying to modify but when I do, the uploaded image doesn't appear, the "image missing" box w/borders and an 'X' in the upper LH Corner is displayed, the mask image does not load either.
 This is how I worked the code:
<?php require_once('../../../../../../../../wp-blog-header.php');
	
	session_start();
	unset($_SESSION['upload_id']);
	unset($_SESSION['front_design']);
	$filename = $_FILES["uploadfile"]["name"];
	$ext = substr(strrchr($filename, "."), 1);
	//$randName = md5(rand() * time());
	//$randName = uniqid();
	$randName = time().uniqid();
	$filename = $randName . '.' . $ext; 
	$_SESSION['front_design'] = $randName;
	$_SESSION['upload_id'] = $filename;
	
									
	if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"],"../cs/uploadImage/" . $filename)){
	//image resize
	$ab_path= plugin_dir_path( __FILE__ ); 
	$img_path = wp_get_image_editor($ab_path.'/uploadImage/'.$filename);
	if (!is_wp_error( $img_path ) ) {
	$img_path->resize(220,220,true);
	$saved = $img_path->save();
	$getpos2=strpos($saved['path'],'/wp-content');
	
	$getstr2=substr($saved['path'],$getpos2);
	
	$resize_file_name=basename($getstr2);
	//BREAK INTO ORIGINAL CODE
	// FIND THE IMAGES	
$original = $resize_file_name;
$h2o_mark = 'http://www.mydomain.com/mymask.png';

// READ THE IMAGE AND THE WATERMARK FILE
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($h2o_mark);

// ADD WATERMARK USING LOCAL FUNCTION
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));

// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);
//RESUME ORIGINAL CODE

	}
	echo $resize_file_name;
	//BREAK BACK INTO ORIGINAL CODE
	// ADD THE MASK
function imagelogo (&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h)
{
    ImageAlphaBlending($dst_image,TRUE);
    ImageAlphaBlending($src_image,TRUE);
    ImageCopy($dst_image, $src_image, ($dst_w-$src_w), ($dst_h-$src_h), 0, 0, $src_w, $src_h);
}
	}
	else{
		echo "error";
	}
?>

Open in new window

Do you have any suggestions at this point?
Thanks Again for your help
0
Mark BradyPrincipal Data EngineerCommented:
Make sure the path is correct for the image and make sure the script has write access to the upload folder. I have used Ray's script in the past and it works great. Nice work Ray!
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Julian HansenCommented:
Do you just want to overlay your image on the uploaded one - or do you actually want to create a modified image that is a composite of the original and the overlay?

You can do the former without any additional php code just using markup and styling.
0
stoneycurtisAuthor Commented:
I hired a programmer to resolve this issue.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stoneycurtisAuthor Commented:
I hired a programmer to write a module for the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.