data-url

Using an image file vs data URI in the CSS

♀尐吖头ヾ 提交于 2020-01-22 12:38:28
问题 I'm trying to decide the best way to include an image that is required for a script I've written. I discovered this site and it made me think about trying this method to include the image as a data URI (defined by RFC 2397) since it was so small - it's a 1x1 pixel 50% opacity png file (used for a background) - it ends up at 2,792 bytes as an image versus 3,746 bytes as text in the CSS. So would this be considered good practice, or would it just clutter up the CSS unnecessarily? 回答1: I don't

canvas.toDataURL() not working properly [duplicate]

风格不统一 提交于 2020-01-13 08:21:09
问题 This question already has answers here : How to return value from an asynchronous callback function? [duplicate] (3 answers) Closed 12 months ago . I am having a canvas in which I upload an image with the following code: function handleImage(e){ var reader = new FileReader(); reader.onload = function(event){ var img = new Image(); img.onload = function(){ canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img,0,0); } img.src = event.target.result; } reader.readAsDataURL(e

Security error“ code: ”1000 on Firefox with Canvas.toDataURL

﹥>﹥吖頭↗ 提交于 2020-01-07 05:08:25
问题 I've got error like jQuery and Canvas.toDataURL Some user told that might run it on server but I run it on my server not local and still got this 'Security error" code: "1000' error. Security error" code: "1000 [Break On This Error] data: 'raw='+canvas.toDataURL("image/png", ""), 回答1: oh I've found solution just change toDataURL('image/png', '') to toDataURL() and it run correctly 来源: https://stackoverflow.com/questions/4984431/security-error-code-1000-on-firefox-with-canvas-todataurl

Javascript previews with new FileReader API and DataURLs seem inefficient

点点圈 提交于 2019-12-30 10:02:29
问题 I am using the new FileReader API to preview images before upload. This is done using DataURLs. But DataURLs can be massive if the images are large. This is especially a problem for me as the user may upload multiple images at a time and previewing the bunch has actually slowed my browser considerably and actually crashed chrome a few times. Is there any alternative to using DataURLs for previewing images on the client before upload? 回答1: You can also store data on the client's disk (in

Javascript previews with new FileReader API and DataURLs seem inefficient

筅森魡賤 提交于 2019-12-30 10:01:57
问题 I am using the new FileReader API to preview images before upload. This is done using DataURLs. But DataURLs can be massive if the images are large. This is especially a problem for me as the user may upload multiple images at a time and previewing the bunch has actually slowed my browser considerably and actually crashed chrome a few times. Is there any alternative to using DataURLs for previewing images on the client before upload? 回答1: You can also store data on the client's disk (in

jQuery and Canvas.toDataURL

非 Y 不嫁゛ 提交于 2019-12-29 09:07:33
问题 I'm working on a script, and a small part of that involves taking a canvas and converting it to a downloadable image. To do this, I do: var thumb_jpeg = thumbnail.toDataURL("image/jpeg"); $("#" + options.dest).attr('src',thumb_jpeg); ...where thumbnail is a canvas tag and options.dest is the name of an img id. This code works perfectly in Chrome, but when I try it in Firefox, Firebug throws up this error: Security error" code: "1000 var thumb_jpeg = thumbnail.toDataURL("image/jpeg"); I would

Canvas toDataUrl increases file size of image

微笑、不失礼 提交于 2019-12-29 04:15:54
问题 When using toDataUrl() to set the source of an image tag I am finding that the image when saved is a great deal larger than the original image. In the example below I am not specifying a second param for the toDataUrl function so the default quality is being used. This is resulting in an image much larger that the original image size. When specifying 1 for full quality the image generated is even larger. Does anybody know why this is happening or how I can stop it? // create image var image =

Downloading file from DataURL in JavaScript

浪子不回头ぞ 提交于 2019-12-20 10:47:16
问题 From this string we get from DataURL, what's the best way to download this as a file? So far what I got was using a basic window.open("myDataURL"); , but I'm not able to change the file name in this way. window.open('data:application/msword;base64,0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAA PgADAP7/CQAGAAAAAAAAAAAAAAACAAAANQAAAAAAA AAAEAAANwAAAAIAAAD+////AAAAADQAAABsAA/', '_blank','height=300,width=400'); I was wondering if there's any way to handle this data properly. 回答1: you can add a download

How do I extract a portion of an image in canvas and use it as background image for a div?

我只是一个虾纸丫 提交于 2019-12-19 19:58:18
问题 This is how my code looks: document.addEventListener('DOMContentLoaded', function () { var canvas = document.querySelector('canvas'); var ctx = canvas.getContext("2d"); var imageData = ctx.getImageData(0, 0, 300, 300); var tile = { 'id': 1, 'data': imageData, 'dataUrl': imageData.toDataUrl() }; var div = document.createElement('div'); div.classList.add('tile'); grid.appendChild(div); div.style.backgroundImage = ('url(' + tile.dataUrl + ')'); }); I'm trying to extract portion of the image on

iPhone Open DATA: Url In Safari

纵然是瞬间 提交于 2019-12-18 12:29:26
问题 I have a Data: URL (see: http://en.wikipedia.org/wiki/Data_URI_scheme) (as a NSString) and I want to open it in Safari. How would you accomplish this (I tried openURL:.) Example: data:text/html;base64,(Some Base64 Encoded Data Here) 回答1: In iPhone OS 2.2.1 and 5.0.1, in both the simulator and on a device, opening a data: url works perfectly in a UIWebView but using openURL does precisely nothing. And Safari will gladly, and properly, render such an URL if you are willing to type one into the