generate LVGL 9 binary
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
45
server/cinema/lib/common/image_resizer.dart
Normal file
45
server/cinema/lib/common/image_resizer.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:image/image.dart' as img;
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@singleton
|
||||
class ImageResizer {
|
||||
static const int maxWidth = 480;
|
||||
static const int maxHeight = 320;
|
||||
|
||||
img.Image resizeToFit(img.Image image) {
|
||||
final w = image.width;
|
||||
final h = image.height;
|
||||
|
||||
if (w <= maxWidth && h <= maxHeight) {
|
||||
return image;
|
||||
}
|
||||
|
||||
final aspectRatio = w / h;
|
||||
int newWidth;
|
||||
int newHeight;
|
||||
|
||||
if (w > h) {
|
||||
newWidth = maxWidth;
|
||||
newHeight = (maxWidth / aspectRatio).round();
|
||||
if (newHeight > maxHeight) {
|
||||
newHeight = maxHeight;
|
||||
newWidth = (maxHeight * aspectRatio).round();
|
||||
}
|
||||
} else {
|
||||
newHeight = maxHeight;
|
||||
newWidth = (maxHeight * aspectRatio).round();
|
||||
if (newWidth > maxWidth) {
|
||||
newWidth = maxWidth;
|
||||
newHeight = (maxWidth / aspectRatio).round();
|
||||
}
|
||||
}
|
||||
|
||||
return img.copyResize(
|
||||
image,
|
||||
width: newWidth,
|
||||
height: newHeight,
|
||||
interpolation: img.Interpolation.linear,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user