image.js 748 Bytes
function imageUtil (originalWidth, originalHeight) {
    const imageSize = {};
    wx.getSystemInfo({
        success (res) {
            const windowWidth = res.windowWidth;
            imageSize.x = 0;
            imageSize.y = 0;
            imageSize.windowWidth = windowWidth;
            imageSize.imageWidth = originalWidth;
            imageSize.imageHeight = originalHeight;
            if (originalWidth > windowWidth) {
                imageSize.imageWidth = windowWidth;
                imageSize.imageHeight = windowWidth * originalHeight / originalWidth;
            } else {
                imageSize.x = (windowWidth - originalWidth) / 2;
            }
        }
    });
    return imageSize;
}

module.exports = {
    imageUtil
};