Skip to content

Instantly share code, notes, and snippets.

@ltvu93
Created May 20, 2020 10:23
Show Gist options
  • Save ltvu93/cd5973efff8349c251715d90322718d2 to your computer and use it in GitHub Desktop.
Save ltvu93/cd5973efff8349c251715d90322718d2 to your computer and use it in GitHub Desktop.
Future<void> loadImage() async {
final response = await http.get(widget.url);
if (response.statusCode == 200) {
imageBytes = response.bodyBytes;
imageRotate = await getRotateFromImageBytes(imageBytes);
setState(() {});
}
}
Future<int> getRotateFromImageBytes(List<int> bytes) async {
int rotate = 0;
if (kIsWeb) {
final Map<String, IfdTag> exifData = await readExifFromBytes(bytes);
if (exifData != null &&
exifData.isNotEmpty &&
exifData.containsKey('Image Orientation')) {
final IfdTag orientation = exifData['Image Orientation'];
final int orientationValue = orientation.values[0];
if (orientationValue == 3) {
rotate = 180;
}
if (orientationValue == 6) {
rotate = -90;
}
if (orientationValue == 8) {
rotate = 90;
}
}
}
return rotate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment