Ishimoto Posted November 23, 2014 Share Posted November 23, 2014 Hi, I'm trying to combine two images - an uploaded image and a permanent. First I try to resize them to the same dimensions. Why I resize the uploaded image to the dimensions of permanent, everything works fine. But when I do the opposite, the images just don't merge, and the output is just the permanent image with resized dimensions. Anyone knows why? Here is my code: <?php if( isset( $_FILES['image'] ) ){ $desired_width = 360; $desired_height = 360; $layers = array(); switch($_FILES['image']['type']){ case "image/jpeg": $source_image = imagecreatefromjpeg($_FILES['image']['tmp_name']); break; case "image/gif": $source_image = imagecreatefromgif($_FILES['image']['tmp_name']); break; case "image/png": $source_image = imagecreatefrompng($_FILES['image']['tmp_name']); break; } $frame = imagecreatefrompng("1.png"); $desired_width = imagesx($source_image); $desired_height = imagesy($source_image); $virtual_image = imagecreatetruecolor($desired_width, $desired_height); imagecopyresampled($virtual_image, $frame, 0, 0, 0, 0, $desired_width, $desired_height, 360, 360); $layers = array($source_image,$virtual_image); $image = imagecreatetruecolor($desired_width, $desired_height); // to make background transparent imagealphablending($image, false); $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127); imagefill($image, 0, 0, $transparency); imagesavealpha($image, true); imagealphablending($image, true); for ($i = 0; $i < count($layers); $i++) { imagecopy($image, $layers[$i], 0, 0, 0, 0, $desired_width, $desired_height); } imagealphablending($image, false); imagesavealpha($image, true); header('Content-type: image/png'); header('Content-Disposition: attachment; filename="new_profile.png"'); imagepng($image); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.