admin管理员组文章数量:1345726
I would like to use createElement("img') to create .jpeg extension instead of .png
According to Flanagan's book JavaScript: The Definitive Guide: Activate Your Web Pages By David Flanagan,
For jpeg image type, the second argument should be a number between 0 and 1 specifying the image quality level.
I am not sure what the syntax for the code would be.
Is it something like this?
createElement("img",1)
I would like to use createElement("img') to create .jpeg extension instead of .png
According to Flanagan's book JavaScript: The Definitive Guide: Activate Your Web Pages By David Flanagan,
For jpeg image type, the second argument should be a number between 0 and 1 specifying the image quality level.
I am not sure what the syntax for the code would be.
Is it something like this?
createElement("img",1)
Share
Improve this question
asked Sep 26, 2011 at 20:56
Jason KimJason Kim
19.1k13 gold badges69 silver badges106 bronze badges
2
- When you create an <img> element, it doesn't actually create an image. It creates an HTML element that can hold an image. You have to then specify the path to that image. What exactly are you trying to do? – John Kurlak Commented Sep 26, 2011 at 21:01
- You really have to buy the book to get that previous page, because there is no "type" attribute to createElement. Flanagan is referring to a different function. – John Kurlak Commented Sep 26, 2011 at 21:04
3 Answers
Reset to default 4The book is talking about html5's canvas tag and specifically its .toDataURL method.
I think you want to do something like:
var img = document.createElement('img');
img.src = 'myImageSource.jpg';
In this case, it's up to the web server to deliver the image and its type information to the web browser.
The book that you're referring to seems to be talking about the toDataURL
method of the canvas
API (see this), which accepts type
and quality
arguments.
You can use document.createElement
without worrying about MIME types or quality.
you can use setAttrebure() Method or built-in 'src' property.
var img = document.createElement('img');
img.setAttibute('src', 'img.jpg');
document.body.appendChild(img);
or use
var img = document.createElement('img');
img.src = "img.jpg";
document.body.appendChild(img);
本文标签: javascriptUsing createElement(39img39) to get jpeg instead of pngStack Overflow
版权声明:本文标题:javascript - Using createElement('img') to get .jpeg instead of .png - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743792642a2539858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论