Skip to content

Instantly share code, notes, and snippets.

@rtio
Created July 25, 2023 20:53
Show Gist options
  • Select an option

  • Save rtio/6a3e08d2b43b6078eefcf2f7af66654f to your computer and use it in GitHub Desktop.

Select an option

Save rtio/6a3e08d2b43b6078eefcf2f7af66654f to your computer and use it in GitHub Desktop.
Convert an image to a byte string
<?php
$webpFilePath = 'new.jpeg';
$byteArray = array_values(unpack('C*', file_get_contents($webpFilePath)));
$byteString = implode(array_map('chr', $byteArray));
echo base64_encode($byteString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment