1
有沒有辦法使用php gd圖像在動畫gif中發出幀?動畫gd幀
有沒有辦法使用php gd圖像在動畫gif中發出幀?動畫gd幀
這不能用GD來完成,但我找到了一個很棒的庫。這有點複雜,所以這裏是一個鏈接到圖書館使用php製作GIF動畫。它解釋瞭如何徹底使用它。 http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html
這裏是一個PHP頁面我提出,將所有這些集成的代碼:
<?php
if(isset($_POST['speed']))
{
header('Content-type: image/gif');
if(isset($_POST['download'])){
header('Content-Disposition: attachment; filename="animated.gif"');
}
include('GIFEncoder.class.php');
function frame($image){
ob_start();
imagegif($image);
global $frames, $framed;
$frames[]=ob_get_contents();
$framed[]=$_POST['speed'];
ob_end_clean();
}
foreach ($_FILES["images"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$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();
}
?>
<form action="" method="post" enctype="multipart/form-data">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery.MultiFile.js"></script>
<script src="jquery.placeholder.js"></script>
<input type="file" name="images[]" class="multi" />
<script>
$(function(){
$('input[placeholder], textarea[placeholder]').placeholder();
});
</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>
<input name="speed" maxlength="10" type="text" placeholder="Speed of frames in ms" onkeypress="return isNumberKey(event)">
<input name="width" maxlength="4" type="text" placeholder="Width" onkeypress="return isNumberKey(event)">
<input name="height" maxlength="4" type="text" placeholder="Height" onkeypress="return isNumberKey(event)">
<input type="submit" name="download" value="Download!">
<input type="submit" name="preview" value="Preview!">
</form>
正如你看到它引用的第一個鏈接上發現的GIFEncoder類。它也使用一些JavaScript驗證和jQuery multiupload。