Early in the morning, there was simultaneous feedback that the picture uploaded by the APP was flipped and the display direction was inconsistent with the actual direction
The first reaction is to compress the image to upload and lose the exIF extension information of the image, so that the Orientation parameters in exIF cannot be found
Exchangeable Image File Format (Exif) is specially set for digital camera photos, which can record the attribute information and shooting data of digital photos.
In the process of taking pictures, it is not always straight, but also horizontally or vertically. Then the camera will record the orientation in the exIF extended information of the picture. If there is no automatic processing in the program, it needs to process according to the orientation to get the correct display effect
That is to ask colleagues to come one of the original map for reinvestigation
View the image extension information. It is recommended to upload the original image using the EXIF viewer to get the following information:
It can be seen that the original image does have a direction parameter, which is rotated 90 degrees, that is, to the right, right
Start debugging, uncompressed upload, but the display result is still rotated, the display effect is not correct
Ossx-oss-process =image/info
{
"FileSize": { "value": "292585" },
"Format": { "value": "jpg" },
"ImageHeight": { "value": "1080" },
"ImageWidth": { "value": "1438" },
"ResolutionUnit": { "value": "1" },
"XResolution": { "value": "1/1" },
"YResolution": { "value": "1/1"}}Copy the code
Visible direction information is lost, then there is a big question, why the original image upload, but the extended information has been lost?
Then I started debugger debugging and used uni.getimageInfo () API to obtain the image information. I found that the orientation of the image was up, which was inconsistent with the actual orientation of the image
{
path: 'file:///storage/emulated/0/Android/data/uni.UNIA98EF91/apps/__UNI__9613C89/doc/uniapp_temp/compressed/1637639926758_ WeChat figure Slice _20211123093640. JPG '.width: 1438.height: 1080.orientation: 'up'.type: 'jpeg'.errMsg: 'getImageInfo:ok'
}
Copy the code
It can be seen that the problem is not caused by the subsequent image compression, but the information has been lost when the image is obtained
Sorin ‘uni-app’ select image using uni.chooseImage() API
Find, this API default sizeType parameter, can choose original original image, compressed image, default both, but found through log printing, will only return compressed image,
{
errMsg: 'chooseImage:ok'.tempFilePaths: [
'file:///storage/emulated/0/Android/data/uni.UNIA98EF91/apps/__UNI__9613C89/doc/uniapp_temp/compressed/1637650175247_ WeChat figure Slice _20211123093640. JPG '].tempFiles: [{path: 'file:///storage/emulated/0/Android/data/uni.UNIA98EF91/apps/__UNI__9613C89/doc/uniapp_temp/compressed/1637650175247_ WeChat figure Slice _20211123093640. JPG '.size: 292585}}]Copy the code
TempFilePaths [0] and tempFiles[0]. Path are the same. They are all compressed image paths
Sorset sizeType to [‘original’]
The image information was obtained through uni.getimageInfo () and it was found that the orientation was right, which was consistent with the original image and normal
{
path: 'file:///storage/emulated/0/$MuMu Shared folder/WeChat picture _20211123093640. The JPG'.width: 4624.height: 3472.orientation: 'right'.type: 'jpeg'.errMsg: 'getImageInfo:ok'
}
Copy the code
Open the following image compression operation plus.zip.pressimage
To upload or display:
If everything is normal, use x-oss-process=image/info to obtain image information
{
ApertureValue: { value: '184/100' },
ExifTag: { value: '154' },
ExposureTime: { value: '700/10000' },
FNumber: { value: '18900/10000' },
FileSize: { value: '430517' },
Make: { value: 'Xiaomi' },
Model: { value: 'Redmi Note 8 Pro' },
Orientation: { value: '6' },
PixelXDimension: { value: '4624' },
PixelYDimension: { value: '3472'}}Copy the code
Image extension information is available (some sensitive parameters, such as GPS positioning information, have been deleted), and Orientation information is not lost
End, scatter flowers, reply to colleagues
Summary on pit
uni.chooseImage()
By default, the API compresses the image and loses the image exif extensionuni.chooseImage()
Is not setsizeType
Parameter, the documentation says defaultoriginal
The original image,compressed
Compression diagrams have both, but really only compression diagrams- use
plus.zip.compressImage
Image compression, no loss of exIF extension information, app is perfect to use - If the original image is required, specify it
sizeType
for['original']