本文共 9520 字,大约阅读时间需要 31 分钟。
Exchangeable image file format
Exif 2.3官方标准(上面wiki内提取)
Python Exif 解析模块
JPEG Rotation and EXIF Orientation 字段,(图像旋转字段解读)
图虫EXIF查看器
imagemagick 分析工具 identify
分析参考:
# magick identify -verbose /Users/bytedance/Downloads/Lark20210112-201836.jpeg Image: Filename: /Users/bytedance/Downloads/Lark20210112-201836.jpeg Format: JPEG (Joint Photographic Experts Group JFIF format) Mime type: image/jpeg Class: DirectClass Geometry: 4032x3024+0+0 Resolution: 72x72 Print size: 56x42 Units: PixelsPerInch Colorspace: sRGB Type: TrueColor Base type: Undefined Endianness: Undefined Depth: 8-bit Channel depth: Red: 8-bit Green: 8-bit Blue: 8-bit Channel statistics: Pixels: 12192768 Red: min: 0 (0) max: 255 (1) mean: 89.0166 (0.349085) median: 31 (0.121569) standard deviation: 60.5416 (0.237418) kurtosis: -0.572173 skewness: 0.588149 entropy: 0.94586 Green: min: 0 (0) max: 255 (1) mean: 109.909 (0.431016) median: 29 (0.113725) standard deviation: 64.9169 (0.254576) kurtosis: -1.18594 skewness: -0.20972 entropy: 0.94162 Blue: min: 0 (0) max: 255 (1) mean: 133.504 (0.523543) median: 35 (0.137255) standard deviation: 73.5451 (0.288412) kurtosis: -1.30359 skewness: -0.406024 entropy: 0.932756 Image statistics: Overall: min: 0 (0) max: 255 (1) mean: 110.81 (0.434548) median: 31.6667 (0.124183) standard deviation: 66.3345 (0.260135) kurtosis: -1.2888 skewness: 0.0306381 entropy: 0.940079 Rendering intent: Perceptual Gamma: 0.454545 Chromaticity: red primary: (0.64,0.33) green primary: (0.3,0.6) blue primary: (0.15,0.06) white point: (0.3127,0.329) Matte color: grey74 Background color: white Border color: srgb(223,223,223) Transparent color: none Interlace: None Intensity: Undefined Compose: Over Page geometry: 4032x3024+0+0 Dispose: Undefined Iterations: 0 Compression: JPEG Quality: 87 Orientation: RightTop Convex hull: 0,0 4031,0 4031,3022 4030,3023 0,3023 0,0 Minimum bounding box: 4031,0 4031,3023 0,3023 0,0 Profiles: Profile-app4: 901284 bytes Profile-exif: 2971 bytes Properties: date:create: 2021-01-12T12:18:38+00:00 date:modify: 2021-01-12T12:16:06+00:00 exif:ApertureValue: 169/100 exif:BrightnessValue: 421/100 exif:ColorSpace: 1 exif:ComponentsConfiguration: 1, 2, 3, 0 exif:DateTime: 2021:01:05 12:06:42 exif:DateTimeDigitized: 2021:01:05 12:06:42 exif:DateTimeOriginal: 2021:01:05 12:06:42 exif:ExifOffset: 207 exif:ExifVersion: 48, 50, 50, 48 exif:ExposureBiasValue: 0/6 exif:ExposureMode: 0 exif:ExposureProgram: 2 exif:ExposureTime: 1/1392 exif:Flash: 16 exif:FlashPixVersion: 48, 49, 48, 48 exif:FNumber: 180/100 exif:FocalLength: 4229/1000 exif:FocalLengthIn35mmFilm: 21 exif:GPSInfo: 2959 exif:ImageLength: 3024 exif:ImageWidth: 4032 exif:InteroperabilityOffset: 2929 exif:LightSource: 0 exif:Make: Xiaomi exif:MaxApertureValue: 169/100 exif:MeteringMode: 2 exif:Model: MIX 3 exif:PhotographicSensitivity: 100 exif:PixelXDimension: 4032 exif:PixelYDimension: 3024 exif:SceneCaptureType: 0 exif:SceneType: 1 exif:SensingMethod: 1 exif:ShutterSpeedValue: 10443/1000 exif:SubSecTime: 629625 exif:SubSecTimeDigitized: 629625 exif:SubSecTimeOriginal: 629625 exif:thumbnail:InteroperabilityIndex: R98 exif:thumbnail:InteroperabilityVersion: 48, 49, 48, 48 exif:WhiteBalance: 0 exif:YCbCrPositioning: 1 jpeg:colorspace: 2 jpeg:sampling-factor: 2x2,1x1,1x1 minimum-bounding-box:_p: 0,0 minimum-bounding-box:_q: 4031,0 minimum-bounding-box:_v: 4030,3023 minimum-bounding-box:angle: 0 minimum-bounding-box:area: 1.21857e+07 minimum-bounding-box:height: 4031 minimum-bounding-box:unrotate: -0 minimum-bounding-box:width: 3023 signature: 42b124e4f580b814e965490ff52904e4f72a123e9605766ba554c32586905476 unknown: 145, 7, 177, 17, 84, 21, 100, 67, 172, 62, 201, 197, 208, 3, 64, 103, 90, 143, 68, 53, 5, 7, 227, 66, 44, 202, 229, 139, 166, 242, 235, 90, 41, 32, 162, 63, 48, 90, 52, 234, 177, 7, 89, 202, 218, 9, 174, 14, 101, 63, 185, 96, 7, 152, 21, 155, 238, 118, 117, 120, 189, 179, 183, 242, 92, 58, 72, 11, 199, 38, 127, 44, 109, 209, 30, 68, 204, 118, 66, 203, 98, 92, 117, 55, 140, 192, 103, 25, 2, 99, 176, 184, 19, 244, 199, 255, 228, 247, 177, 51, 109, 223, 38, 81, 74, 204, 5, 74, 4, 168, 178, 241, 253, 119, 32, 96, 106, 89, 80, 88, 169, 16, 157, 238, 36, 166, 127, 162, 104, 240, 106, 189, 8, 20, 129, 175, 4, 83, 83, 10, 40, 151, 104, 138, 173, 97, 4, 229, 113, 126, 20, 242, 69, 177, 45, 42, 145, 62, 15, 5, 71, 168, 166, 46, 50, 228, 164, 129, 79, 130, 254, 71, 118, 16, 87, 61, 136, 183, 152, 102, 81, 36, 189, 186, 38, 119, 6, 43, 217, 51, 87, 11, 1, 113, 227, 93, 166, 193, 63, 91, 246, 154, 141, 21, 124, 138, 125, 134, 205, 173, 97, 187, 177, 225, 118, 61, 174, 213, 212, 7, 249, 73, 230, 145, 76, 130, 4, 166, 171, 18, 96, 229, 215, 218, 154, 211, 55, 93, 11, 89, 41, 43, 135, 201, 9, 87, 248, 135, 56, 33, 81, 87, 21, 71, 18, 189, 184, 66, 25, 45, 121, 157, 20, 53, 138, 157, 57, 174, 167, 121, 35, 245, 110, 224, 212, 118, 35, 121, 38, 57, 130, 91, 84, 44, 7, 131, 35, 54, 231, 147, 66, 16, 152, 101, 112, 152, 146, 156, 45, 143, 111, 165, 160, 53, 232, 244, 203, 240, 70, 138, 116, 140, 226, 190, 229, 78, 10, 123, 213, 140, 202, 91, 109, 252, 10, 134, 148, 215, 134, 91, 227, 103, 126, 141, 228, 49, 41, 72, 234, 28, 131, 84, 40, 219, 73, 243, 250, 49, 207, 156, 154, 44, 238, 208, 27, 220, 97, 153, 64, 138, 214, 45, 184, 212, 17, 48, 231, 112, 25, 240, 97, 220, 37, 92, 125, 237, 27, 78, 34, 136, 49, 100, 65, 7, 65, 255, 173, 80, 74, 179, 52, 33, 15, 206, 16, 83, 50, 202, 126, 226, 96, 176, 155, 243, 134, 216, 176, 42, 209, 90, 147, 168, 128, 4, 208, 175, 121, 251, 161, 151, 96, 152, 181, 17, 66, 43, 184, 100, 31, 137, 249, 153, 240, 165, 197, 217, 163, 166, 10, 180, 14, 64, 51, 193, 247, 92, 116, 120, 30, 198, 74, 215, 145, 159, 103, 62, 240, 150, 245, 209, 205, 242, 81, 85, 205, 168, 49, 95, 87, 186, 209, 47, 5, 217, 3, 66, 238, 64, 159, 53, 240, 249, 90, 113, 44, 233, 194, 207, 164, 151, 147, 201, 8, 135, 38, 169, 68, 192, 161, 40, 14, 180, 87, 25, 243, 92, 58, 42, 113, 189, 137, 47, 132, 184, 80, 75, 95, 89, 90, 58, 134, 21, 45, 115, 122, 252, 186, 89, 39, 205, 250, 173, 119, 191, 253, 218, 186, 0, 111, 169, 160, 114, 116, 176, 214, 78, 192, 196, 68, 133, 115, 48, 209, 153, 223, 176, 194, 97, 21, 101, 111, 102, 121, 82, 230, 9, 68, 27, 5, 167, 240, 216, 10, 130, 65, 142, 30, 52, 46, 78, 253, 13, 188, 182, 216, 101, 6, 129, 32, 10, 126, 37, 107, 15, 169, 34, 57, 31, 96, 242, 207, 146, 137, 250, 20, 231, 142, 131, 167, 237, 32, 214, 222, 213, 188, 210, 187, 48, 195, 94, 64, 89, 12, 243, 236, 69, 51, 95, 33, 111, 146, 210, 170, 246, 191, 255, 166, 153, 195, 104, 20, 246, 112, 73, 99, 116, 14, 191, 105, 172, 78, 53, 123, 55, 49, 197, 218, 122, 180, 118, 35, 63, 29, 9, 113, 168, 134, 237, 82, 229, 89, 235, 252, 64, 207, 128, 43, 159, 94, 63, 175, 79, 254, 69, 246, 72, 13, 224, 244, 144, 79, 128, 187, 126, 45, 42, 94, 98, 180, 235, 158, 110, 175, 84, 96, 214, 41, 182, 141, 189, 194, 148, 251, 188, 150, 222, 50, 120, 2, 225, 49, 122, 160, 117, 125, 195, 7, 122, 223, 38, 140, 228, 33, 16, 240, 4, 171, 74, 184, 214, 85, 163, 67, 244, 142, 168, 178, 25, 115, 211, 47, 148, 214, 221, 133, 46, 165, 119, 65, 145, 241, 170, 107, 195, 118, 48, 231, 116, 149, 178, 7, 40, 189, 94, 94, 142, 113, 253, 209, 74, 223, 73, 83, 211, 52, 94, 94, 243, 91, 196, 208, 55, 15, 126, 144, 227, 88, 251, 118, 80, 81, 31, 14, 96, 42, 85, 12, 103, 4, 12, 21, 118, 179, 132, 56, 152, 186, 181, 163, 242, 226, 182, 58, 200, 21, 158, 251, 184, 120, 224, 47, 56, 222, 136, 53, 16, 136, 247, 107, 124, 59, 156, 59, 175, 68, 115, 3, 211, 233, 210, 250, 17, 26, 41, 17, 140, 114, 154, 193, 123, 31, 212, 42, 138, 13, 204, 61, 109, 41, 93, 109, 56, 168, 240, 197, 232, 160, 36, 182, 254, 141, 224, 117, 104, 151, 216, 145, 102, 13, 175, 89, 249, 237, 193, 39, 30, 165, 79, 17, 234 Artifacts: verbose: true Tainted: False Filesize: 2.62243MiB Number pixels: 12.1928M Pixels per second: 49.273MP User time: 0.240u Elapsed time: 0:01.247 Version: ImageMagick 7.0.10-54 Q16 x86_64 2021-01-02 https://imagemagick.org
python 模块 exifread 获取:
import exifreadfrom PIL import Imagedef read_img_and_correct_exif_orientation(path): im = Image.open(path) tags = { } with open(path, 'rb') as f: tags = exifread.process_file(f, details=False) if "Image Orientation" in tags.keys(): orientation = tags["Image Orientation"] print("Orientation: %s (%s)", orientation, orientation.values) val = orientation.values if 5 in val: val += [4,8] if 7 in val: val += [4, 6] if 3 in val: print("Rotating by 180 degrees.") im = im.transpose(Image.ROTATE_180) if 4 in val: print("Mirroring horizontally.") im = im.transpose(Image.FLIP_TOP_BOTTOM) if 6 in val: print("Rotating by 270 degrees.") im = im.transpose(Image.ROTATE_270) if 8 in val: print("Rotating by 90 degrees.") im = im.transpose(Image.ROTATE_90) return imim = read_img_and_correct_exif_orientation("/Users/a/Downloads/test.jpeg")print("im : {}".format(im))
输出结果:
Orientation: %s (%s) Rotated 90 CW [6]Rotating by 270 degrees.im :
转载地址:http://gqfli.baihongyu.com/