Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API picture - get picture information


May 18, 2021 WeChat Mini Program Development Document


Table of contents


wx.getImageInfo(Object object)

Get picture information. The network picture needs to be configured with the download domain name before it can take effect.

Parameters

Object object

Property Type The default Required Description
Src string Is The path of the picture, supporting the network path, the local path, and the code pack path
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.success callback function

Parameters
Object res
Property Type Description The lowest version
width number The original width of the picture, in px. Rotation is not considered.
height number The original height of the picture, in px. Rotation is not considered.
path string The local path of the picture
orientation string The orientation of the device when taking a picture 1.9.90
type string Picture format 1.9.90

The legal value of res.orientation

Value Description The lowest version
up The default orientation (phone holding a photo), corresponding to 1 in Exif. or no orientation information.
up-mirrored Same up, but mirror flip, corresponding to 2 in Exif
down Rotate 180 degrees to 3 in Exif
down-mirrored same down, but mirror flip, corresponding to 4 in Exif
left-mirrored Same left, but mirror flip, corresponding to 5 in Exif
right Rotate 90 degrees clockwise to 6 in Exif
right-mirrored Same right, but mirror flip, corresponding to 7 in Exif
left Rotate 90 degrees counterclockwise to 8 in Exif

Sample code

wx.getImageInfo({
  src: 'images/a.jpg',
  success (res) {
    console.log(res.width)
    console.log(res.height)
  }
})

wx.chooseImage({
  success (res) {
    wx.getImageInfo({
      src: res.tempFilePaths[0],
      success (res) {
        console.log(res.width)
        console.log(res.height)
      }
    })
  }
})