image.js 658 B

123456789101112131415161718192021222324
  1. function imageUtil (originalWidth, originalHeight) {
  2. let imageSize = {}
  3. wx.getSystemInfo({
  4. success: function (res) {
  5. const windowWidth = res.windowWidth
  6. imageSize.x = 0
  7. imageSize.y = 0
  8. imageSize.windowWidth = windowWidth
  9. imageSize.imageWidth = originalWidth
  10. imageSize.imageHeight = originalHeight
  11. if (originalWidth > windowWidth) {
  12. imageSize.imageWidth = windowWidth
  13. imageSize.imageHeight = windowWidth * originalHeight / originalWidth
  14. } else {
  15. imageSize.x = (windowWidth - originalWidth) / 2
  16. }
  17. }
  18. })
  19. return imageSize
  20. }
  21. module.exports = {
  22. imageUtil: imageUtil
  23. }