mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-21 11:32:30 +08:00
* [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * [APP-934] add submit logic * Added replace remediation action * Add submit logic * Add submit alt text logic, generate AI alt text * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add AI generate request, add convert from SVG to png base64, added manual fix block * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation * Add texts, add remediation submit, fix logic to store remediation --------- Co-authored-by: Raz Ohad <admin@bainternet.info>
38 lines
870 B
PHP
38 lines
870 B
PHP
<?php
|
|
|
|
namespace EA11y\Modules\Scanner\Classes;
|
|
|
|
use Exception;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly
|
|
}
|
|
|
|
class Utils {
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public static function create_tmp_file_from_png_base64( $base64_string ): string {
|
|
// Check if the base64 string starts with 'data:image/png;base64,'
|
|
if ( preg_match( '/^data:image\/png;base64,(.+)$/', $base64_string, $matches ) ) {
|
|
$base64_data = $matches[1];
|
|
} else {
|
|
throw new Exception( 'Invalid base64 PNG format' );
|
|
}
|
|
|
|
// Decode the base64 data
|
|
$image_data = base64_decode( $base64_data );
|
|
|
|
if ( false === $image_data ) {
|
|
throw new Exception( 'Failed to decode base64 PNG' );
|
|
}
|
|
|
|
// Save the image to a temporary file
|
|
$tmp_path = tempnam( sys_get_temp_dir(), 'png_' ) . '.png';
|
|
file_put_contents( $tmp_path, $image_data );
|
|
|
|
return $tmp_path;
|
|
}
|
|
|
|
|
|
}
|