0

I am facing a major issue in encoding/decoding a base 64 image.

My purpose is to save a canvas image as base64 decoded string that can later be base64 encoded in php.

I have the javascript code as follows:

var string= canvas.toDataURL("image/jpeg");
var abc = window.atob(string.split(",")[1]);
var blob = "HEADERS"+abc;

blob is the file.

PHP code:

$Data = blob File
$img = substr($Data, $start, $end);
$img = base64_encode($img);

I start when I find chr(0xFF) . chr(0xD8) in the blob file and end when I find chr(0xFF) . chr(0xD9)

These characters are not found when I decode through javascript but easily gets found when using base64_decode of php. There is a problem of encoding type I think and I'm a novice in the encoding methods. so kindly help.

gapc311
  • 463
  • 2
  • 6
  • 15
  • 1
    Why don't you send the base64 string to your PHP script and call `base64_decode` on the incoming data? – huysentruitw Jan 29 '18 at 15:22
  • Directly sending it to php and decoding there will work but I wanted to send decoded base64 string since it is smaller in size. Base64 encoded string consumes more size and thus it would take more time in the ajax call to php. – gapc311 Feb 01 '18 at 14:17

0 Answers0