encode image to base64
import base64
file = 'deer.jpg'
image = open(file, 'rb')
image_read = image.read()
image_64_encode = base64.encodebytes(image_read) #encodestring also works aswell as decodestring
print('This is the image in base64: ' + str(image_64_encode))
image_64_decode = base64.decodebytes(image_64_encode)
image_result = open('deer_decode.jpg', 'wb') # create a writable image and write the decoding result
image_result.write(image_64_decode)
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
Also in PHP:
- check if something is on a string php
- clear docker cache
- docker lumen phpunit the request php extension dom is missing
- create user teable ceder
- delete packages laravel
- clear cache in laravel without artisan
- array_column in php
- add seeder in laravel
- add days in php
- array key exists php child child nodes
- find if substring is in string php
- error reporting in php means
- codeigniter where order by
- crud operations in php
- Uncaught RedisException: Redis server went away in
- check if part of the srint is in other string php
- convert time() to date php
- Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in
- eloquent seeds down
- create table seeder laravel
- Connect to SQL in a php PDO and print the data in it
- actual date php
- ci db query error
- Auth::getUser();