createImageMetadataText function
Creates a text description of image metadata including dimensions and source path.
Implementation
String? createImageMetadataText(ImageDimensions dims, {String? sourcePath}) {
final originalWidth = dims.originalWidth;
final originalHeight = dims.originalHeight;
final displayWidth = dims.displayWidth;
final displayHeight = dims.displayHeight;
if (originalWidth == null ||
originalHeight == null ||
displayWidth == null ||
displayHeight == null ||
displayWidth <= 0 ||
displayHeight <= 0) {
if (sourcePath != null) return '[Image source: $sourcePath]';
return null;
}
final wasResized =
originalWidth != displayWidth || originalHeight != displayHeight;
if (!wasResized && sourcePath == null) return null;
final parts = <String>[];
if (sourcePath != null) parts.add('source: $sourcePath');
if (wasResized) {
final scaleFactor = originalWidth / displayWidth;
parts.add(
'original ${originalWidth}x$originalHeight, displayed at '
'${displayWidth}x$displayHeight. Multiply coordinates by '
'${scaleFactor.toStringAsFixed(2)} to map to original image.',
);
}
return '[Image: ${parts.join(', ')}]';
}