function createImage(width) {

    //  创建width*width的jpg格式的图片，背景为黑色，随机生成1000个像素点，颜色为白色，大小从1到5像素不等
    var canvas = document.createElement('canvas');
    canvas.width = width;
    canvas.height = width;
    var context = canvas.getContext('2d');
    context.fillStyle = 'black';
    context.fillRect(0, 0, width, width);
    for (var i = 0; i < 10000; i++) {
        var x = Math.random() * width;
        var y = Math.random() * width;
        var size = Math.random() * 3;
        context.fillStyle = 'white';
        context.fillRect(x, y, size, size);
    }
    var dataUrl = canvas.toDataURL('image/jpeg');


    //  将这个图片插入到id为img1的img元素中
    var img1 = document.getElementById('img1');
    img1.src = dataUrl;

    return dataUrl;
    var image = new Image();
    image.src = dataUrl;

    return image;
    //  将这个图片插入到id为img1的img元素中
    //var img1 = document.getElementById('img1');
    //img1.src = dataUrl;


}

export default createImage;