두 개의 서로 다른 JPEG 파일에서 애니메이션 GIF를 생성 할 수 있다면 x 초 동안 한 이미지를 표시 한 다음 다른 이미지를 표시하는 등의 작업이 가능합니다.PHP - 두 개의 JPEG 이미지에서 간단한 애니메이션 GIF를 만드시겠습니까?
감사의 말.
감사합니다.
두 개의 서로 다른 JPEG 파일에서 애니메이션 GIF를 생성 할 수 있다면 x 초 동안 한 이미지를 표시 한 다음 다른 이미지를 표시하는 등의 작업이 가능합니다.PHP - 두 개의 JPEG 이미지에서 간단한 애니메이션 GIF를 만드시겠습니까?
감사의 말.
감사합니다.
PHP가 기본으로 제공되는 표준 GD 기능을 사용하여 사용할 수 없습니다.
이 경우 class on phpclasses.org이 있습니다. 나는 그것을 직접 사용한 적이 없지만 다른 많은 패키지에서 사용된다.
MagickWand 라이브러리 또는 명령 줄을 사용하여 PHP에서 ImageMagick에 액세스 할 수있는 경우 사용하십시오. ImageMagick을 사용하면 아무런 문제가 없습니다.
합니다 (IM 설명서에서)이 GD 수행 할 수 없습니다하지만 난 그것을 위해 좋은 라이브러리를 발견했다. 그래도 조금 복잡하기 때문에 여기에 php로 애니메이션 gif를 만드는 라이브러리 링크가 있습니다. 그것을 철저히 사용하는 방법을 설명합니다. http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html
두 장의 사진을 선택하고 너비와 높이에 대해 속도 900으로 100을 씁니다. 애니메이션 GIF 슬라이드 쇼에 넣을 것입니다. 당신이 첫 번째 링크에있는 GIFEncoder 클래스를 참조시피
<?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>
: 여기
는 해당 스크립트 코드입니다. 또한 일부 자바 스크립트 유효성 검사 및 jQuery 다중 업로드를 사용합니다.참고 :이 질문은 이미 요청되었습니다.
멋진 최신 솔루션을 보려면 this SO answer을 참조하십시오.
더 최근의 해결책은 here is my fork이며 작은 수정 번호가 & 개입니다. 실제 애플리케이션에서 그것의 예 :
가$anim = new GifCreator\AnimGif();
$gif = $anim->create($image_files);
//file_put_contents("test.gif", $gif);
header("Content-type: image/gif");
echo $gif;
(GD2로 PHP5.3 요구.)
예 PHP 5.6 GD 2.4.11 작동 :
require_once "AnimGif.php";
/*
* Create an array containing file paths, resource var (initialized with imagecreatefromXXX),
* image URLs or even binary code from image files.
* All sorted in order to appear.
*/
$image_files = array(
//imagecreatefrompng("/../images/pic1.png"), // Resource var
//"/../images/pic2.png", // Image file path
//file_get_contents("/../images/pic3.jpg"), // Binary source code
'https://yt3.ggpht.com/-KxeE9Hu93eE/AAAAAAAAAAI/AAAAAAAAAAA/D-DB1Umuimk/s100-c-k-no-mo-rj-c0xffffff/photo.jpg', // URL
'https://media.licdn.com/mpr/mpr/shrinknp_100_100/AAEAAQAAAAAAAAloAAAAJDRkZGY2MWZmLTM1NDYtNDBhOS04MjYwLWNkM2UzYjdiZGZmMA.png', // URL
'http://is5.mzstatic.com/image/thumb/Purple128/v4/e4/63/e7/e463e779-e6d0-0c3d-3ec1-97fdbaae230a/source/100x100bb.jpg' // URL
);
/*
* Create an array containing the duration (in millisecond) of each frame.
*/
$durations_millis = array(
1000,
2000,
3000
);
/*
* Fix durations.
*/
$durations = array();
for ($i = 0; $i < count($durations_millis); $i++) {
$durations[$i] = $durations_millis[$i]/10;
}
/*
* Specify number of loops. (0 = infinite looping.)
*/
$num_loops = 0;
/*
* Create gif object.
*/
$anim_gif = new GifCreator\AnimGif();
$gif_object = $anim_gif->create($image_files, $durations, $num_loops);
/*
* Get the animated GIF binary.
*/
$gif_binary = $gif_object->get();
/*
* Set the file name of the saved/returned animated GIF.
*/
$file_name = "animated.gif";
/*
* Optionally, save animated GIF in a folder as a GIF:
*/
//file_put_contents($file_name, $gif_binary);
/*
* Optionally, return the animated GIF to client.
*/
header("Content-type: image/gif");
header('Content-Disposition: filename="' . $file_name . '"'); // Optional
echo $gif_binary;
/*
* All done.
*/
exit;
내 (PHP5.6, GD2.4.11)에서는 작동하지 않습니다. 그냥 '이미지'를 줘."오류가 있기 때문에 표시 할 수 없습니다." –
@ ban-geoengineering, 지적 해 주셔서 고맙습니다. (글쎄, 가능한 것은 PHP5.6이 없었기 때문입니다.) 가능한 수정 사항이 코드에 병합되었습니다 다시 시도해주세요. 문제가 남아있는 경우 GitHub의 프로젝트에 문제를 제출하여 올바르게 처리 할 수 있습니다. –
감사합니다. 작업 코드 스 니펫으로 답변을 업데이트했습니다. –
** phpclasses.org ** 코드는 악몽에 액세스 할 수 있으며 입력 파일은 GIF 파일이어야합니다. JPEG 파일에서는 작동하지 않습니다. -/ –
다른 정적 질문에 대한이 답변을 사용하여 입력 JPEG 이미지를 (정적) GIF 이미지로 변환 할 수 있습니다. https://stackoverflow.com/a/755843/1617737 –