From 0fee7f84c73799c10408582faede7a31c9915c69 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Thu, 6 Oct 2022 22:32:41 +0300 Subject: [PATCH] img to base64 --- content/posts/2022/image-to-base64.md | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 content/posts/2022/image-to-base64.md diff --git a/content/posts/2022/image-to-base64.md b/content/posts/2022/image-to-base64.md new file mode 100644 index 0000000..fc96f67 --- /dev/null +++ b/content/posts/2022/image-to-base64.md @@ -0,0 +1,50 @@ +--- +title: "Преобразование изображений в Base64 строку" +date: 2022-10-06T22:25:08+03:00 +draft: false +tags: [linux, tips] +--- + +В ОС Linux есть стандартная утилита `base64`, которая на вход принимает данные. + +> base64 присутсвует даже в [BusyBox](https://www.busybox.net/BusyBox.html) +(Ctrl+F > base64) + +Ниже представлен пример, которые скачивает **SVG** код **twemoji** +и преобразует его с строку **base64**. + +```sh +curl https://raw.githubusercontent.com/twitter/twemoji/master/assets/svg/1f4a2.svg | base64 + +% Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed +100 994 100 994 0 0 3228 0 --:--:-- --:--:-- --:--:-- 3259 + +PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNiAz +NiI+PHBhdGggZmlsbD0iI0JFMTkzMSIgZD0iTTIuNjM4IDIzLjgyMWwtMS42MjUtMy4xIDEuNTUt +LjgxMmMyLjM5My0xLjI1NSA0Ljk4Mi0yLjc3OCA1LjQxMy00Ljk4Mi4zMzUtMS43MTQtLjYxMS0z +LjkwMy0yLjgxMi02LjUwNmwtMS4xMy0xLjMzNiAyLjY3Mi0yLjI2IDEuMTMgMS4zMzZjMi45NjEg +My41MDIgNC4xMzEgNi41ODkgMy41NzQgOS40MzctLjc4OCA0LjAzNy00Ljk3NSA2LjIzMS03LjIy +MyA3LjQxbC0xLjU0OS44MTN6TTIwLjkzIDM0Ljk0N2wtLjgxMi0xLjU1Yy0xLjI1NS0yLjM5NC0y +Ljc3OC00Ljk4Mi00Ljk4Mi01LjQxMy0xLjcxMy0uMzM2LTMuOTAzLjYxMS02LjUwNiAyLjgxMmwt +MS4zMzYgMS4xMy0yLjI2LTIuNjcyIDEuMzM2LTEuMTNjMy41MDEtMi45NjIgNi41ODUtNC4xMzQg +OS40MzctMy41NzQgNC4wMzcuNzg4IDYuMjMxIDQuOTc0IDcuNDEgNy4yMjNsLjgxMiAxLjU1LTMu +MDk5IDEuNjI0em04LjUzMS00LjAyMmwtMS4xMy0xLjMzNkMyNS4zNjkgMjYuMDg3IDI0LjIgMjMg +MjQuNzU3IDIwLjE1MWMuNzg4LTQuMDM2IDQuOTc0LTYuMjMgNy4yMjMtNy40MDlsMS41NS0uODEy +IDEuNjI1IDMuMS0xLjU1LjgxMmMtMi4zOTQgMS4yNTUtNC45ODIgMi43NzgtNS40MTMgNC45ODEt +LjMzNSAxLjcxNS42MTEgMy45MDMgMi44MTEgNi41MDZsMS4xMyAxLjMzNi0yLjY3MiAyLjI2em0t +Ny43MDgtMTkuNTg4Yy0uNDcxIDAtLjkzNC0uMDQ1LTEuMzkyLS4xMzQtNC4wMzctLjc4OC02LjIz +MS00Ljk3NS03LjQxLTcuMjIzbC0uODEyLTEuNTUgMy4xLTEuNjI1LjgxMyAxLjU1YzEuMjU1IDIu +MzkzIDIuNzc4IDQuOTgyIDQuOTgxIDUuNDEzIDEuNzExLjMzNCAzLjkwMi0uNjEgNi41MDYtMi44 +MTJsMS4zMzYtMS4xMyAyLjI2IDIuNjcyLTEuMzM2IDEuMTNjLTIuOTQxIDIuNDg2LTUuNTg4IDMu +NzA5LTguMDQ2IDMuNzA5eiIvPjwvc3ZnPg== +``` + +Остаётся только подставить данные типа (MIME) и использовать строку +в любимом ЯП. + +Для **SVG** строка будет выглядеть так: + +```text +data:image/svg+xml;base64, +```