Created
September 24, 2025 17:59
-
-
Save symisc/1b1e2bb4219f613aee91bf758c9cffe4 to your computer and use it in GitHub Desktop.
Programmatically remove text and watermarks from input images using the PixLab TXT-REMOVE API endpoint - https://pixlab.io/endpoints/text-watermark-remove-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Programmatically remove text & watermarks from input images using the PixLab TXT-REMOVE API endpoint. | |
# | |
# Refer to the official documentation at: https://pixlab.io/endpoints/text-watermark-remove-api for the API reference | |
# guide and more code samples. | |
# Use POST to upload the image directly from your local folder. If your image is publicly available | |
# then make a simple GET request with a link to your image. | |
$url = 'https://api.pixlab.io/txtremove'; | |
$apiKey = 'PIXLAB_API_KEY'; // PixLab API Key - Get yours from https://console.pixlab.io/ | |
$imagePath = './local_image.png'; // The local image we are going to remove text from | |
$outputFilename = 'output_image'; | |
$ch = curl_init(); | |
$postData = [ | |
'key' => $apiKey, | |
'file' => new CURLFile(realpath($imagePath)) | |
]; | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
$reply = json_decode($response, true); | |
if ($reply['status'] != 200) { | |
echo $reply['error'] . PHP_EOL; | |
} else { | |
$imgData = $reply['imgData']; // Base64 encoding of the output image | |
$mimeType = $reply['mimeType']; // MIME type (i.e image/jpeg, etc.) of the output image | |
$extension = $reply['extension']; // File extension (e.g., 'png', 'jpeg') | |
// Decode base64 and save to disk | |
try { | |
$imgBytes = base64_decode($imgData); | |
$outputFilename = $outputFilename . "." . $extension; | |
file_put_contents($outputFilename, $imgBytes); | |
echo "Text Removed Image saved to: " . $outputFilename . PHP_EOL; | |
} catch (Exception $e) { | |
echo "Error saving output image: " . $e->getMessage() . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Programmatically remove text and watermarks from input images using the PixLab TXT-REMOVE API endpoint - https://pixlab.io/endpoints/text-watermark-remove-api