0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Juliaで画像をBase64に変換する方法

Last updated at Posted at 2024-04-05

画像→Base64に変換

Matrix形式の画像をBase64形式に変換する方法。以下はplaceholder.comから取得した画像をカットしてJPEGのBase64形式に変換するサンプル。

using Images
using FileIO
using HTTP
using ImageMagick
using Base64

res = HTTP.get("https://via.placeholder.com/200x200")
img = ImageMagick.load_(res.body)
println(size(img))
cut_img = img[1:size(img)[1]÷2, 1:size(img)[2]÷2]

io = IOBuffer()
save(Stream(format"JPEG", io), cut_img)
img_base64 = base64encode(take!(io))
println(img_base64)
# /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgM ...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?