Skip to content

Instantly share code, notes, and snippets.

@kodaka
Created July 30, 2013 03:48
Show Gist options
  • Save kodaka/6110071 to your computer and use it in GitHub Desktop.
Save kodaka/6110071 to your computer and use it in GitHub Desktop.
convert file to data URI
#!/usr/bin/env perl
use strict;
use warnings;
use File::Slurp;
use MIME::Base64;
use Plack::MIME;
my $file = shift or die "usage: $0 file¥n";
my $mime = Plack::MIME->mime_type($file) or die "Cannot find MIME type for $file";
printf 'data:%s;base64,%s', $mime, encode_base64(read_file($file, { binmode => ':raw' }), q{});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment