Skip to content

Instantly share code, notes, and snippets.

@swdevbali
Created May 12, 2024 12:24
Show Gist options
  • Save swdevbali/398e208dafa249ed78aa458ed055005b to your computer and use it in GitHub Desktop.
Save swdevbali/398e208dafa249ed78aa458ed055005b to your computer and use it in GitHub Desktop.
import pandas as pd
import base64
# Buat DataFrame kosong
df = pd.DataFrame(columns=['Image'])
# Contoh gambar-gambar dengan "5 digit letter-number sequence"
gambar1 = 'abcde.png'
gambar2 = 'fghij.png'
# Baca gambar dan ubah menjadi base64
with open(gambar1, "rb") as img_file:
img1_base64 = base64.b64encode(img_file.read()).decode('utf-8')
with open(gambar2, "rb") as img_file:
img2_base64 = base64.b64encode(img_file.read()).decode('utf-8')
# Masukkan representasi base64 ke dalam DataFrame
df.loc[0] = [img1_base64]
df.loc[1] = [img2_base64]
# Simpan DataFrame ke dalam file CSV
df.to_csv('gambar.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment