I have a JQUERY image cropping plugin that stores a cropped result as Base64/JPEG. I'd like to save that Base64 IMG as an actual JPG in a folder called IMAGES in the root.
The example screenshot below shows you the Base64 image that I would like saved as file. The SAVE button doesn't do anything right now, but should perform my desired function.
I assume there will be some PHP as well that does the saving to IMAGES part. It would also be good if it saves the image file with some random name (IE - not image.jpg, but image_random52.jpg)
<input id="save_to_file" type="button" value="Save" onClick="MaybeSomethingShouldGoHERE???()"></div>
Also, here is the relevant PHP code that generated that Base64 Image.
$resizedImage = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW,
$imgH, $imgInitW, $imgInitH);
$dest_image = imagecreatetruecolor($cropW, $cropH);
imagecopyresampled($dest_image, $resizedImage, 0, 0, $imgX1, $imgY1, $cropW,
$cropH, $cropW, $cropH);
ob_start();
imagejpeg($dest_image, null, $jpeg_quality);
$imgData = ob_get_clean();
ob_end_clean();
$response = array(
"status" => 'success',
"url" => 'data:'.$what['mime'].';base64,'.base64_encode($imgData),
);
echo json_encode($response);
UPDATED PHP CODE
$response = array(
"status" => 'success',
"url" => 'data:'.$what['mime'].';base64,'.base64_encode($imgData),
$final_output = 'data:'.$what['mime'].';base64,'.base64_encode($imgData)
);
$decoded=base64_decode($final_output);
file_put_contents('newImage.JPG',$decoded);
//leave it to you to randomize the filename.