show in jquery a table of inbox imap mail

Home » Snippets » show in jquery a table of inbox imap mail

Created with:




Customize With AI
// wp-plugin.php

// Capture text from image using OCR and define text position
function wp_plugin_capture_text_with_ocr($attachment_id, $x, $y, $width, $height) {
    // Get the image path
    $upload_dir = wp_upload_dir();
    $image_path = $upload_dir['basedir'] . '/' . get_post_meta($attachment_id, '_wp_attached_file', true);

    // Check if the image file exists
    if (!file_exists($image_path)) {
        return false;

    // Prepare the image data for API
    $image_data = base64_encode(file_get_contents($image_path));

    // Define the API configuration
    $api_key = 'your-ocr-space-api-key'; // Replace with your API key
    $api_url = '';

    // Prepare the OCR request parameters
    $parameters = array(
        'apikey' => $api_key,
        'language' => 'eng', // Replace with the desired language code
        'isTable' => 'true',
        'OCREngine' => '2',
        'detectOrientation' => 'true',
        'scale' => 'true',
        'OCRLanguage' => 'eng',
        'region' => $x . ',' . $y . ',' . $width . ',' . $height,
        'base64Image' => $image_data,

    // Send the OCR request
    $response = wp_remote_post($api_url, array(
        'body' => $parameters,

    // Check if the request was successful
    if (is_wp_error($response)) {
        return false;

    // Get the parsed OCR response
    $parsed_response = json_decode($response['body'], true);

    // Check if OCR was successful
    if ($parsed_response['IsErroredOnProcessing']) {
        return false;

    // Get the extracted text from the OCR response
    $extracted_text = $parsed_response['ParsedResults'][0]['ParsedText'];

    return $extracted_text;



This code modifies the existing wp_plugin_capture_text_from_image function to include the ability to define the text position using the API.

The function now takes additional parameters $x, $y, $width, and $height, which represent the coordinates and dimensions of the region of interest (ROI) within the image where the text is located.

Inside the function, the OCR request is prepared by encoding the image data using base64_encode and setting up the API configuration. You'll need to replace 'your-ocr-space-api-key' with your actual API key.

The OCR request parameters are defined based on the API documentation. The region parameter is set using the provided $x, $y, $width, and $height parameters to define the text position within the image.

The OCR request is sent using the wp_remote_post function, which sends an HTTP POST request to the API endpoint with the provided parameters.

The response from the API is checked for errors, and if successful, the extracted text is returned.

Please note that you need to have a valid API key to use this code. Also, ensure that you have the necessary permissions to read the image file and make API requests.

Make sure to add proper error handling, validation, and security measures to suit your specific needs before using this code in a production environment.

Register an account to save your snippets or go Pro to get more features.