data-uri

How do you base-64 encode a PNG image for use in a data-uri in a CSS file?

非 Y 不嫁゛ 提交于 2019-11-27 00:41:34
I want to base-64 encode a PNG file, to include it in a data:url in my stylesheet. How can I do that? I’m on a Mac, so something on the Unix command line would work great. A Python-based solution would also be grand. Jon This should do it in Python: import base64 encoded = base64.b64encode(open("filename.png", "rb").read()) In python3, base64.b64encode returns a bytes instance, so it's necessary to call decode to get a str , if you are working with unicode text. # Image data from [Wikipedia][1] >>>image_data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x05\x00\x00\x00\x05\x08\x06\x00

How to create an ArrayBuffer and data URI from Blob and File objects without FileReader?

我是研究僧i 提交于 2019-11-26 22:01:30
问题 This Question is related to and inspired by How to updoad in old browsers (ex Safari 5.1.4) Given an <input type="file"> element having a files property containing File objects which inherit from Blob , is it possible to create a ArrayBuffer and convert the ArrayBuffer to a data URI from a Blob or File object without using FileReader ? Approaches have tried so far have been create a mock WebSocket with .binaryType set to "arraybuffer" , create a MessageEvent with event.data set to File object

PHP Data-URI to file

只谈情不闲聊 提交于 2019-11-26 15:59:49
I have a data URI I am getting from javascript and trying to save via php. I use the following code which gives a apparently corrupt image file: $data = $_POST['logoImage']; $uri = substr($data,strpos($data,",")+1); file_put_contents($_POST['logoFilename'], base64_decode($uri)); data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs 9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAxklEQVQYlYWQMW7CUBBE33yITYUUmwbOkBtEcgUlTa7COXIVV5RUkXKC5AxU EdyZVD4kyKxkwIrr9vd0c7Oih aopinLNsF6Qkg2XW4XJ7LGFsAAcTV6lF5/jLdbALA9XDAXYfthFQVx OrmqKYK88/7rbbMFksALieTnzu9wDYTj6f70PKsp2kwAiSvjXNcvkWpAfNZkzWa

Why use data URI scheme?

为君一笑 提交于 2019-11-26 15:22:21
问题 Basically the question is in the title. Many people have had the question stackoverflow of how to create a data URI and problems therein. My question is why use data URI? What are the advantages to doing: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /> Over doing: <img src="dot.png" alt="Red dot" /> I understand one has less overhead on the server side (maybe), but what are

What is Data URI support like in major email client software?

瘦欲@ 提交于 2019-11-26 15:22:19
Data URIs are a standard way to embed images and other binary data in HTML, and browser support is well documented on the web. (IE8 was the first version of IE to support Data URI, with a max 32 KB size per URI; other major browsers have supported it even longer.) My question is about desktop email and webmail client software. When building HTML email, standard practice is either to include images as attachments or load them externally (i.e. tracking images). Both of these have disadvantages (some clients list all of these attached files, while many rightly block or require user action to see

Convert HTML to data:text/html link using JavaScript

倖福魔咒の 提交于 2019-11-26 15:13:44
Here's my HTML: <a>View it in your browser</a> <div id="html"> <h1>Doggies</h1> <p style="color:blue;">Kitties</p> </div> How do I use JavaScript to make the href attribute of my link point to a base64 encoded webpage whose source is the innerHTML of div#html ? I basically want to do the same conversion done here (with the base64 checkbox checked) except for in JavaScript. Characteristics of a data-URI A data-URI with MIME-type text/html has to be in one of these formats: data:text/html,<HTML HERE> data:text/html;charset=UTF-8,<HTML HERE> Base-64 encoding is not necessary. If your code

“Aw, Snap” when data uri is too large

早过忘川 提交于 2019-11-26 12:27:28
问题 I\'m writing a chrome extension which does the following: Downloads a file from a website to memory using XMLHttpRequest Adds additional data to the file and then base64 encodes the result to the variable total_encoded_data Offers the data to the user using <a href=data:application/octet-stream;charset=utf-8;base64,\' + total_encoded_data+\' download=\'file.bin\'>Click to Download</a> . Where total_encoded_data is added to href using jQuery. I have found, through a manual binary search, that

Cross-browser Save As .txt

假装没事ソ 提交于 2019-11-26 11:31:51
问题 Is there a JavaScript library that allows to save strings as txt files, and works cross-browser? In the past, I have been using Downloadify, but I am looking at another option for a couple reasons: I hope to find a pure JavaScript solution, without the need for Flash it seems that Downloadify is not updated anymore (no update in the past 18 months) I am experiencing an issue with Downloadify in IE 9, where strings are cut off 回答1: As far as I know, the only way is to use data: URLs to force a

Send a base64 image in HTML email

亡梦爱人 提交于 2019-11-26 11:18:44
Using a rich-text editor, our users can drag and drop a saved image from their desktop to the editor. The image appears and displays properly in the web page after they submit. Since the image is not uploaded anywhere, the editor saves the image as a base64-encoded image. <img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4QAAAFKCAIAAADKUQaBAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAP+lSURBVHhepP1p32zb etc. But it doesn't show up - not on the iPhone, nor two different versions of Outlook. The image is simply broken. We want to stick with base64 due to it

How do you base-64 encode a PNG image for use in a data-uri in a CSS file?

半城伤御伤魂 提交于 2019-11-26 09:25:45
问题 I want to base-64 encode a PNG file, to include it in a data:url in my stylesheet. How can I do that? I’m on a Mac, so something on the Unix command line would work great. A Python-based solution would also be grand. 回答1: This should do it in Python: import base64 encoded = base64.b64encode(open("filename.png", "rb").read()) 回答2: In python3, base64.b64encode returns a bytes instance, so it's necessary to call decode to get a str , if you are working with unicode text. # Image data from