Base64-Codierung von Bildern in Python 3

Ein Hinweis auf den Code, mit dem das Bild mit WebSocket codiert und anschließend mit Base64 gesendet wird. Gibt es einen einfacheren Weg?

import base64

img_file = 'hoge.jpg'
b64 = base64.encodestring(open(img_file, 'rb').read())
try:
    # Python2                                                                                                                                                          
    print('b64=' + b64)
except TypeError:
    # Python3                                                                                                                                                          
    print('b64=' + b64.decode('utf8'))

Recommended Posts

Base64-Codierung von Bildern in Python 3
Kodierung des Urteils in Python
Python-Codierung
Zahlenerkennung in Bildern mit Python
Bildpixel-Manipulation in Python
So sammeln Sie Bilder in Python
Extrahieren Sie mit Python Text aus Bildern
Arbeiten mit DICOM-Bildern in Python
Quadtree in Python --2
Python in der Optimierung
CURL in Python
Geokodierung in Python
SendKeys in Python
Metaanalyse in Python
Unittest in Python
Wenden Sie verschiedene Formen von Mosaiken auf Bilder an (Python, OpenCV).
Was ich mit json.dumps in Pythons base64-Codierung süchtig gemacht habe
So setzen Sie die Standardcodierung in Python auf utf-8
Epoche in Python
Zwietracht in Python
Deutsch in Python
DCI in Python
Quicksort in Python
nCr in Python
N-Gramm in Python
Programmieren mit Python
Plink in Python
Konstante in Python
[python, openCV] base64 Gesichtserkennung in Bildern
Laden Sie Bilder von der URL-Liste in Python herunter
FizzBuzz in Python
SQLite in Python
Schritt AIC in Python
LINE-Bot [0] in Python
CSV in Python
Reverse Assembler mit Python
Reflexion in Python
Konstante in Python
nCr in Python.
Format in Python
Scons in Python 3
Puyopuyo in Python
Python in Virtualenv
PPAP in Python
Quad-Tree in Python
Reflexion in Python
Chemie mit Python
Hashbar in Python
Entfernen Sie DICOM-Bilder in Python
DirectLiNGAM in Python
Lesen von Zeichen in Bildern mit Python OCR
LiNGAM in Python
In Python reduzieren
In Python flach drücken
[Python] Speichern Sie Bilder, die mit Selenium auf Leinwand gezeichnet wurden (ActionChains, PyAutoGUI, base64 usw.).
Konvertieren Sie PDFs mit Python in Massenbilder
Hinweis zur Codierung bei LANG = C in Python
DICOM-Bilder mit Python Part 2 entfernen
Zeichenkodierung beim Umgang mit Dateien in Python 3