canvasResize - Issues converting base64 string to image file (PHP)

Apr 6, 2016

I had to use canvasResize (jQuery plugin) to resize images before uploading them to the server. The plugin returns a base64 string that I was trying to convert to an image on the PHP server without success. After way too much time mucking around I discovered that the string was containing text at the start that meant it was not valid base64. This was possibly being added by the canvasResize plugin though that is speculation at this stage.

I resolved the issue by using string replace to remove the extraneous text of "data:image/jpeg;base64,". See below for sample of code used:
str_replace("data:image/jpeg;base64,", "", $base64String);