/
home
/
efamember
/
domains
/
efa-member.com
/
public_html
/
main
/
up file
home
<?php if (isset($_POST['image'])) { // $data = $_POST['image']; // $data = str_replace('data:image/png;base64,', '', $data); // $data = str_replace(' ', '+', $data); // $decodedData = base64_decode($data); // Retrieve base64-encoded image data from POST request $base64ImageData = $_POST['image']; // Remove the data prefix (e.g., "data:image/png;base64,") list(, $base64ImageData) = explode(';', $base64ImageData); list(, $base64ImageData) = explode(',', $base64ImageData); // Decode base64 data $decodedImageData = base64_decode($base64ImageData); // Create an image resource from the decoded data $image = imagecreatefromstring($decodedImageData); // Get the dimensions of the image $width = imagesx($image); $height = imagesy($image); // Create a new true-color image with a transparent background $outputImage = imagecreatetruecolor($width, $height); $transparentColor = imagecolorallocatealpha($outputImage, 0, 0, 0, 127); imagefill($outputImage, 0, 0, $transparentColor); imagesavealpha($outputImage, true); // Set the color of the background to be removed (white in this case) $whiteColor = imagecolorallocate($image, 255, 255, 255); // Loop through each pixel in the input image for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $pixelColor = imagecolorat($image, $x, $y); // If the pixel color is not white, copy it to the output image if ($pixelColor !== $whiteColor) { imagesetpixel($outputImage, $x, $y, $pixelColor); } } } // Set the path to your output PNG file $outputFile = 'upload/join/signature/output.png'; // Save the resulting image to the output file imagepng($outputImage, $outputFile); // Free up memory by destroying the image resources imagedestroy($image); imagedestroy($outputImage); echo 'Background removed and image saved successfully!'; } else { echo 'Error: No signature data received.'; }