mirror of
https://github.com/immich-app/immich.git
synced 2026-01-26 11:24:44 -08:00
28 lines
953 B
Dart
28 lines
953 B
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
Rect convertCropParametersToRect(CropParameters parameters, int originalWidth, int originalHeight) {
|
|
return Rect.fromLTWH(
|
|
parameters.x.toDouble() / originalWidth,
|
|
parameters.y.toDouble() / originalHeight,
|
|
parameters.width.toDouble() / originalWidth,
|
|
parameters.height.toDouble() / originalHeight,
|
|
);
|
|
}
|
|
|
|
CropParameters convertRectToCropParameters(Rect rect, int originalWidth, int originalHeight) {
|
|
final x = (rect.left * originalWidth).round();
|
|
final y = (rect.top * originalHeight).round();
|
|
final width = (rect.width * originalWidth).round();
|
|
final height = (rect.height * originalHeight).round();
|
|
|
|
return CropParameters(
|
|
x: max(x, 0).clamp(0, originalWidth),
|
|
y: max(y, 0).clamp(0, originalHeight),
|
|
width: max(width, 0).clamp(0, originalWidth - x),
|
|
height: max(height, 0).clamp(0, originalHeight - y),
|
|
);
|
|
}
|