diff --git a/resources/js/components/AltTextGeneratorInputsFieldtype.vue b/resources/js/components/AltTextGeneratorInputsFieldtype.vue index c0eceac..4920c93 100644 --- a/resources/js/components/AltTextGeneratorInputsFieldtype.vue +++ b/resources/js/components/AltTextGeneratorInputsFieldtype.vue @@ -43,7 +43,7 @@ export default { if (labelNode.querySelector('.generate-button')) { return; } - + // Create button and add listener const btn = document.createElement('button'); btn.className = 'generate-button'; btn.id = 'generate-button'; @@ -68,6 +68,7 @@ export default { const parent = e.currentTarget.closest('.form-group'); const selectedInput = parent.querySelector('.input-group') .querySelector('.input-text'); + // Get text language from text field if (selectedInput.getAttribute('id') === 'field_alt_de') { language = 'de'; } else if (selectedInput.getAttribute('id') === 'field_alt_fr') { diff --git a/src/Controllers/AltTextGeneratorController.php b/src/Controllers/AltTextGeneratorController.php index 4b32e93..fe9004b 100644 --- a/src/Controllers/AltTextGeneratorController.php +++ b/src/Controllers/AltTextGeneratorController.php @@ -33,6 +33,7 @@ public function submitData(Request $request) echo json_encode($responseData); } + // Process image data and send request to AltText.ai API public function generateAltText(string $url, string $textLanguage) { $imageDataService = new ImageDataService(); diff --git a/src/Services/ImageDataService.php b/src/Services/ImageDataService.php index 4447436..7672bd7 100644 --- a/src/Services/ImageDataService.php +++ b/src/Services/ImageDataService.php @@ -14,15 +14,15 @@ public function processImageUrl(string $url): string ); $imagePath = $_SERVER['DOCUMENT_ROOT'] . strtr($url, $replacements); - $rawData = $this->encodeImage($imagePath); - return $rawData; + // Image gets converted to base64 string to circumvent browserlock on stage + return $this->encodeImage($imagePath); } public function encodeImage(string $imagePath): string { $image = file_get_contents($imagePath); - $rawData = base64_encode($image); - - return $rawData; + //Encode the image to base64 and remove the prefix to get raw data + $imageData = base64_encode($image); + return preg_replace('#^data:image/[^;]+;base64,#', '', $imageData); } }