fileReference; $mimeType = (string)$file->getMimeType(); $extension = strtolower((string)$file->getExtension()); // Alt-text fallback (Seobility: 215 pages with empty alt): the // reference title, then the file's title property. Editors can // still override per reference. if (trim((string)($data['alt'] ?? '')) === '') { $fallbackAlt = trim((string)($file->getTitle() ?? '')); if ($fallbackAlt === '') { $fallbackAlt = trim((string)($file->getOriginalFile()->getProperty('title') ?? '')); } if ($fallbackAlt !== '') { $data['alt'] = $fallbackAlt; } } $data['mimeType'] = $mimeType; $data['size'] = (int)$file->getSize(); if (!str_starts_with($mimeType, 'image/') || in_array($extension, self::SKIP_EXTENSIONS, true)) { if (str_starts_with($mimeType, 'image/')) { $data['width'] = (int)$file->getProperty('width'); $data['height'] = (int)$file->getProperty('height'); } return $data; } $crop = null; if ($file->hasProperty('crop') && $file->getProperty('crop')) { $cropArea = CropVariantCollection::create((string)$file->getProperty('crop'))->getCropArea('default'); if (!$cropArea->isEmpty()) { $crop = $cropArea->makeAbsoluteBasedOnFile($file); } } $imageService = GeneralUtility::makeInstance(ImageService::class); $instructions = static fn (int $width): array => array_filter([ 'width' => $width, 'crop' => $crop, 'fileExtension' => 'webp', ], static fn ($v) => $v !== null); $default = $imageService->applyProcessingInstructions($file, $instructions(self::DEFAULT_WIDTH)); $srcset = []; foreach (self::SRCSET_WIDTHS as $width) { $variant = $imageService->applyProcessingInstructions($file, $instructions($width)); if ($variant->usesOriginalFile()) { continue; } $srcset[] = [ 'url' => $imageService->getImageUri($variant, true), 'width' => (int)$variant->getProperty('width'), 'descriptor' => (int)$variant->getProperty('width') . 'w', ]; } $data['originalUrl'] = (string)($data['publicUrl'] ?? ''); $data['originalSize'] = (int)$file->getSize(); $data['publicUrl'] = $imageService->getImageUri($default, true); $data['width'] = (int)$default->getProperty('width'); $data['height'] = (int)$default->getProperty('height'); $data['size'] = (int)$default->getSize(); $data['srcset'] = $srcset; $data['mimeType'] = (string)($default->getMimeType() ?: 'image/webp'); } catch (\Throwable $e) { // keep the stock payload } return $data; } }