我可以保存图像,但它是黑色的

时间:2016-07-23 11:51:42

标签: php jquery image-processing crop image-uploading

我正在使用名为cropit的漂亮工具并构建了一个小应用程序:You can check it out here

现在我尝试保存图像,而不是在新窗口中打开它。我用过这个:

JQUERY:

$('.export').click(function() {
    var imageData = $('#image-cropper').cropit('export');
    $.post('upload.php', { imageData: imageData }, function() {
      alert("success");
    })
});

PHP:

$imageData = $_POST['imageData'];
$decoded = urldecode($imageData);
$exp = explode(',', $decoded);
$base64 = array_pop($exp);
$data = base64_decode($base64);
$file = 'data.png';
file_put_contents($file, $data);

结果我在我的目录中得到一个PNG文件,当我打开时没有出错(我可以缩放和做东西),但它是空白的。如何使图像显示在文件中?

0 个答案:

没有答案