dojo: download image and detect pixel size

2019-08-22 17:32发布

I need to perform the following task:

  1. download an image by a given URL
  2. detect the size of that image in pixels or in kb, whatever is easier

Does anybody know a good approach with dojo or with "plain JavaScript"?

1条回答
何必那么认真
2楼-- · 2019-08-22 18:16

Is this simple approach sufficient? I'm not sure if you meant "download" to mean "save to the client's computer" or simply "retrieve from the remote server".

<script type="text/javascript">
    var image = new Image();
    image.onload = function() {
        alert("Width: " + image.width + ", Height: " + image.height);
    }
    image.src = "http://placehold.it/350x150";
</script>
查看更多
登录 后发表回答