Creating Images from base64
Posted: Thu Mar 01, 2012 6:48 pm
Hey Guys,
I am trying to create an jpg image from base64 code. Here's what I've got, in the first forum is a canvas drawing and it is captured by a JavaScript script which then saves it as a base64, in either img/jpeg or img/png. I was then able to take the base64 and attach it to an hidden text value in the forum to be able to grab it by PHP in my next page where I process the information. When I processes the information I want to save the base64 information as a jpg image in a folder, I have been able to save a file as .jpg into the folder but when I try and open it in Photoshop I get this error "Could not complete your request because a JPEG marker segment length is to short.".
This is the code I am using to get the saved .jpg file:
$imgSrc = $_POST['i1'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
//print $imgSrc;
file_put_contents('./images/signatures/' . $firstName . '-' . $lastName . '.jpg', $_POST['i1']);
My guess is that the line of base64 data is being "stored" into the .jpg like a text file and that's why it isn't being read. I was wondering if there is anyway of being able to take that base64 code and creating a image with it?
Thanks!
I am trying to create an jpg image from base64 code. Here's what I've got, in the first forum is a canvas drawing and it is captured by a JavaScript script which then saves it as a base64, in either img/jpeg or img/png. I was then able to take the base64 and attach it to an hidden text value in the forum to be able to grab it by PHP in my next page where I process the information. When I processes the information I want to save the base64 information as a jpg image in a folder, I have been able to save a file as .jpg into the folder but when I try and open it in Photoshop I get this error "Could not complete your request because a JPEG marker segment length is to short.".
This is the code I am using to get the saved .jpg file:
$imgSrc = $_POST['i1'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
//print $imgSrc;
file_put_contents('./images/signatures/' . $firstName . '-' . $lastName . '.jpg', $_POST['i1']);
My guess is that the line of base64 data is being "stored" into the .jpg like a text file and that's why it isn't being read. I was wondering if there is anyway of being able to take that base64 code and creating a image with it?
Thanks!