我的问题是,我用gifshot.js插件录制了一个gif,并且想要保存它现在什么不waork。我使用ajax函数将src字符串发送到php,然后解码base64字符串(正常工作)。在那之后,gif将被保存在你将在下面看到的目录中,但它不会工作。很沮丧......你有什么方法吗?
HTML:
<section id="reingif" class="gifshot-image-preview-section" style="height: 210.7px; width: 210.7px;">
<img src="data:image/gif;base64,ROIGODIh9AH0AQAAA...">
</section>
jQuery的:
$("#create-gif").click(function(){
gifshot.createGIF({
gifWidth: 500,
gifHeight: 500,
interval: 0.2,
numFrames: 25,
sampleInterval:7,
numWorkers: 3
}, function (obj) {
if (!obj.error) {
var image = obj.image, animatedImage = document.createElement('img');
animatedImage.src = image;
$("#reingif").html(animatedImage);
var viewportHeight = $(window).height();
var gifdims = 0.7 * viewportHeight + "px";
$("#reingif img").addClass("addcrimg").height(gifdims).width(gifdims);
var datastring = $("#reingif img").attr('src');
$.ajax({
url: 'savegif.php',
type: 'post',
dataType: 'text',
data: { 'base64data' : datastring }
});
}
});
});
PHP:
@$base64data = mysqli_real_escape_string($db, trim(htmlspecialchars($_POST["username"])));
$decodedpic = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $base64data));
file_put_contents('/images/saved.gif', $decodedpic);