How to Get a Base64 Version of a File From Command Line
A while back I wrote an article on how to Convert Image to Data URI with JavaScript. It’s a neat trick developers can use for any number of reasons. Instead of abusing canvas, however, why not simply get the base64 data from command line?
You can use base64
and pbcopy
to convert a file to base64 and copy it to the clipboard:
# base64 gets data, pbcopy copies to clipboard base64 -i logo.jpeg | pbcopy
Once you have the file data copied in base64 format, the URL format to use the data is:
# data:{mime-type};base64,{data} data:image/jpeg;base64,/9j/4AAQSkZJRgAB......
While base64 data and data URIs do look cryptic, they’re useful to avoid making requests to other files. I use them when creating presentations or when I can’t count on a decent internet connection.
Contents
7 Essential JavaScript Functions
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like
addEventListener
andattachEvent
. Times have changed but there are still a few functions each developer should…CSS vs. JS Animation: Which is Faster?
How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point…
jQuery UI DatePicker: Disable Specified Days
One project I’m currently working on requires jQuery. The project also features a datepicker for requesting a visit to their location. jQuery UI’s DatePicker plugin was the natural choice and it does a really nice job. One challenge I encountered was the…
MooTools Star Ratings with MooStarRating
I’ve said it over and over but I’ll say it again: JavaScript’s main role in web applications is to enhance otherwise boring, static functionality provided by the browser. One perfect example of this is the Javascript/AJAX-powered star rating systems that have become popular over the…
[ad_2]
Source link