我一直在寻找使用php生成gif的解决方案。我发现了一个,但我无法将gif插入我的服务器文件夹。我试图上传jpeg图像,我使用move_uploaded_files,它运作良好。但是使用此代码生成gif,move_uploaded_files对它不起作用。有没有人知道如何将生成的gif移动到我的文件夹而不将其作为附件下载?
<?php
require "../IP/config.php";
if(isset($_POST['preview']))
{
header('Content-type: image/gif');
if(isset($_POST['download'])){
// header('Content-Disposition: attachment; filename="animated.gif"');
//$insert="INSERT INTO content(image,name,address,contactno,price,star_rating,room_qty,userid) VALUES ('animated','est','test','123','120','3','3','1')";
//mysqli_query($con,$insert);
}
include('GIFEncoder.class.php');
function frame($image){
ob_start();
imagegif($image);
global $frames, $framed;
$frames[]=ob_get_contents();
$framed[]=50;
ob_end_clean();
}
$cnt = count($_FILES['images']['name']);
for($key=0;$key<$cnt;$key++)
{
$tmp_name = $_FILES["images"]["tmp_name"][$key];
$im = imagecreatefromstring(file_get_contents($tmp_name));
$resized = imagecreatetruecolor($_POST['width'],$_POST['height']);
imagecopyresized($resized, $im, 0, 0, 0, 0, $_POST['width'], $_POST['height'], imagesx($im), imagesy($im));
frame($resized);
}
$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
echo $gif->GetAnimation();
$filepath="../IP/image".$_POST['width'];
//move_uploaded_file($gif,$filepath);
copy($gif,$filepath);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='robots' content='index,follow' />
<title>Create GIF image using php</title>
<script src="jquery-latest.js"></script>
<script src="jquery.MultiFile.js"></script>
<script src="jquery.placeholder.js"></script>
<style>
input{
margin:10px;
padding:10px;
}
.center{
width:205px;
border:1px solid #000;
border-radius:5px;
padding:10px;
clear:both;
}
</style>
</head>
<center>
<div id="forms" class="menu">
<h1>GIF Generator</h1>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="images[]" multiple>
</script>
<script language=Javascript>
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
<div class="center">
<label>SPEED:</label><br>
<input name="speed" maxlength="10" type="text" placeholder="Speed in MS" onKeyPress="return isNumberKey(event)" style="padding:5px;"><br><br>
<label>WIDTH: </label><br>
<input name="width" maxlength="4" type="text" placeholder="Width" onKeyPress="return isNumberKey(event)" style="padding:5px;"><br><br>
<label>HEIGHT: </label><br>
<input name="height" maxlength="4" type="text" placeholder="Height" onKeyPress="return isNumberKey(event)" style="padding:5px;"><br><br>
<input type="submit" style="padding:10px; background:#00A2E4; border-radius:5px; font-weight:bold; color:#fff;" name="preview" value="Preview">
<input type="submit" style="padding:10px; background:#15A915; border-radius:5px; font-weight:bold; color:#fff;" name="download" value="Download">
</div>
</form>
</div>
</center>
</html>