最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flash - Pure Javascript image handling library (in binary form, not through DOM) - Stack Overflow

programmeradmin8浏览0评论

Since File API will enable access to the content of local files it is now possible to do image resize before upload (a fairly mon task) without any additional technology like Flash or Silverlight. Except that I can't find any Javascript library that would be able to handle images in binary form. Is there any? Maybe there is some in Flashe's ECMA script that could be adapted, but I simply can't find anything.

Since File API will enable access to the content of local files it is now possible to do image resize before upload (a fairly mon task) without any additional technology like Flash or Silverlight. Except that I can't find any Javascript library that would be able to handle images in binary form. Is there any? Maybe there is some in Flashe's ECMA script that could be adapted, but I simply can't find anything.

Share Improve this question asked Mar 3, 2010 at 8:46 calavera.infocalavera.info 1,2002 gold badges15 silver badges30 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Although I haven't find such libs, I have found a way how to acplish the described task:

  • Read image as Data URL
  • Load an image into a canvas tag and resize it
  • Encode canvas image data into some image format, for example JPG. Or use Canvas.toDataUrl() and then (optionaly) some base64 decoder.

Client side image resizing and upload with pure javascript. That's cool, isn't it?

Even if you do find something that understands images in pure javascript, you would still need the DOM to render it, making it incredibly slow.

Don't know if this is what you want, but there are some scripts on Userscripts that handle images: http://userscripts/scripts/show/38736

One problem with calavera.info's answer (sorry I cannot seem to ment directly on that answer) is that the call to either CanvasRenderingContext2D.getImageData or Canvas.toDataURL mentioned in the third bullet will fail. They each throw a SECURITY_ERR: DOM Exception 18 as the image is not from the same origin or domain as the document that owns the canvas element. That seems inevitable since the image es from the local file system (via an input type="file" tag), but the page es from your web server.

发布评论

评论列表(0)

  1. 暂无评论