PHP之生成GIF动画的实现方法_php技巧
gif 애니메이션
php
생성하다
代码如下所示:
class GifMerge {
var $ver = '1.1';
var $dly = 50;
var $mod = 'C_FILE';
var $first = true;
var $use_loop = false;
var $transparent = false;
var $use_global_in = false;
var $x = 0;
var $y = 0;
var $ch = 0;
var $fin = 0;
var $fout = '';
var $loop = 0;
var $delay = 0;
var $width = 0;
var $height = 0;
var $trans1 = 255;
var $trans2 = 255;
var $trans3 = 255;
var $disposal = 2;
var $out_color_table_size = 0;
var $local_color_table_flag = 0;
var $global_color_table_size = 0;
var $out_color_table_sizecode = 0;
var $global_color_table_sizecode= 0;
var $gif = array(0x47, 0x49, 0x46);
var $buffer = array();
var $local_in = array();
var $global_in = array();
var $global_out = array();
var $logical_screen_descriptor = array();
function GifMerge($images, $t1, $t2, $t3, $loop, $dl, $xpos, $ypos, $model) {
if($model) {
$this->mod = $model;
}
if($loop > -1) {
$this->loop = floor($loop - 1);
$this->use_loop = true;
}
if($t1 > -1 && $t2 > -1 && $t3 > -1) {
$this->trans1 = $t1;
$this->trans2 = $t2;
$this->trans3 = $t3;
$this->transparent = true;
}
for($i = 0; $i $dl[$i] ? $this->delay = $dl[$i] : $this->delay = $this->dly;
$xpos[$i] ? $this->x = $xpos[$i] : $this->x = 0;
$ypos[$i] ? $this->y = $ypos[$i] : $this->y = 0;
$this->start_gifmerge_process($images[$i]);
}
$this->fout .= "/x3b";
}
function start_gifmerge_process($fp) {
if($this->mod == 'C_FILE') {
if(!$this->fin = fopen($fp, 'rb')) {
return;
}
} elseif($this->mod == 'C_MEMORY') {
$this->ch = 0;
$this->fin = $fp;
}
$this->getbytes(6);
if(!$this->arrcmp($this->buffer, $this->gif, 3)) {
return;
}
$this->getbytes(7);
if($this->first) $this->logical_screen_descriptor = $this->buffer;
$this->global_color_table_sizecode = $this->buffer[4] & 0x07;
$this->global_color_table_size = 2 global_color_table_sizecode;
if($this->buffer[4] & 0x80) {
$this->getbytes((3 * $this->global_color_table_size));
for($i = 0; $i global_color_table_size)); $i++) {
$this->global_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $this->global_color_table_size;
$out_color_table_sizecode = $this->global_color_table_sizecode;
$this->global_out = $this->global_in;
}
if($this->global_color_table_size != $this->out_color_table_size || $this->arrcmp($this->global_out, $this->global_in, (3 * $this->global_color_table_size))) {
$this->use_global_in = true;
}
}
for($loop = true; $loop;) {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0x21:
$this->read_extension();
break;
case 0x2c:
$this->read_image_descriptor();
break;
case 0x3b:
$loop = false;
break;
default:
$loop = false;
}
}
if($this->mod == 'C_FILE') {
fclose($this->fin);
}
}
function read_image_descriptor() {
$this->getbytes(9);
$head = $this->buffer;
$this->local_color_table_flag = ($this->buffer[8] & 0x80) ? true : false;
if($this->local_color_table_flag) {
$sizecode = $this->buffer[8] & 0x07;
$size = 2 $this->getbytes(3 * $size);
for($i = 0; $i $this->local_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $size;
$out_color_table_sizecode = $sizecode;
for($i = 0; $i {
$this->global_out[$i] = $this->local_in[$i];
}
}
}
if($this->first) {
$this->first = false;
$this->fout .= "/x47/x49/x46/x38/x39/x61";
if($this->width && $this->height) {
$this->logical_screen_descriptor[0] = $this->width & 0xFF;
$this->logical_screen_descriptor[1] = ($this->width & 0xFF00) >> 8;
$this->logical_screen_descriptor[2] = $this->height & 0xFF;
$this->logical_screen_descriptor[3] = ($this->height & 0xFF00) >> 8;
}
$this->logical_screen_descriptor[4] |= 0x80;
$this->logical_screen_descriptor[5] &= 0xF0;
$this->logical_screen_descriptor[6] |= $this->out_color_table_sizecode;
$this->putbytes($this->logical_screen_descriptor, 7);
$this->putbytes($this->global_out, ($this->out_color_table_size * 3));
if($this->use_loop) {
$ns[0] = 0x21;
$ns[1] = 0xFF;
$ns[2] = 0x0B;
$ns[3] = 0x4e;
$ns[4] = 0x45;
$ns[5] = 0x54;
$ns[6] = 0x53;
$ns[7] = 0x43;
$ns[8] = 0x41;
$ns[9] = 0x50;
$ns[10] = 0x45;
$ns[11] = 0x32;
$ns[12] = 0x2e;
$ns[13] = 0x30;
$ns[14] = 0x03;
$ns[15] = 0x01;
$ns[16] = $this->loop & 255;
$ns[17] = $this->loop >> 8;
$ns[18] = 0x00;
$this->putbytes($ns, 19);
}
}
if($this->use_global_in) {
$outtable = $this->global_in;
$outsize = $this->global_color_table_size;
$outsizecode = $this->global_color_table_sizecode;
} else {
$outtable = $this->global_out;
$outsize = $this->out_color_table_size;
}
if($this->local_color_table_flag) {
if($size == $this->out_color_table_size && !$this->arrcmp($this->local_in, $this->global_out, $size)) {
$outtable = $global_out;
$outsize = $this->out_color_table_size;
} else {
$outtable = $this->local_in;
$outsize = $size;
$outsizecode = $sizecode;
}
}
$use_trans = false;
if($this->transparent) {
for($i = 0; $i if($outtable[3 * $i] == $this->trans1 && $outtable [3 * $i + 1] == $this->trans2 && $outtable [3 * $i + 2] == $this->trans3) {
break;
}
}
if($i $transindex = $i;
$use_trans = true;
}
}
if($this->delay || $use_trans) {
$this->buffer[0] = 0x21;
$this->buffer[1] = 0xf9;
$this->buffer[2] = 0x04;
$this->buffer[3] = ($this->disposal $this->buffer[4] = $this->delay & 0xff;
$this->buffer[5] = ($this->delay & 0xff00) >> 8;
$this->buffer[6] = $use_trans ? $transindex : 0;
$this->buffer[7] = 0x00;
$this->putbytes($this->buffer,8);
}
$this->buffer[0] = 0x2c;
$this->putbytes($this->buffer,1);
$head[0] = $this->x & 0xff;
$head[1] = ($this->x & 0xff00) >> 8;
$head[2] = $this->y & 0xff;
$head[3] = ($this->y & 0xff00) >> 8;
$head[8] &= 0x40;
if($outtable != $this->global_out) {
$head[8] |= 0x80;
$head[8] |= $outsizecode;
}
$this->putbytes($head,9);
if($outtable != $this->global_out) {
$this->putbytes($outtable, (3 * $outsize));
}
$this->getbytes(1);
$this->putbytes($this->buffer,1);
for(;;) {
$this->getbytes(1);
$this->putbytes($this->buffer,1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
$this->putbytes($this->buffer, $u);
}
}
function read_extension() {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0xf9:
$this->getbytes(6);
break;
case 0xfe:
for(;;) {
$this->getbytes(1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0x01:
$this->getbytes(13);
for(;;) {
$this->getbytes(0);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0xff:
$this->getbytes(9);
$this->getbytes(3);
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
break;
default:
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
}
}
function arrcmp($b, $s, $l) {
for($i = 0; $i if($s{$i} != $b{$i}) {
return false;
}
}
return true;
}
function getbytes($l) {
for($i = 0; $i if($this->mod == 'C_FILE') {
$bin = unpack('C*', fread($this->fin, 1));
$this->buffer[$i] = $bin[1];
} elseif($this->mod == 'C_MEMORY') {
$bin = unpack('C*', substr($this->fin, $this->ch, 1));
$this->buffer[$i] = $bin[1];
$this->ch++;
}
}
return $this->buffer;
}
function putbytes($s, $l) {
for($i = 0; $i $this->fout .= pack('C*', $s[$i]);
}
}
function getAnimation() {
return $this->fout;
}
}
?>
复制代码 代码如下:
class GifMerge {
var $ver = '1.1';
var $dly = 50;
var $mod = 'C_FILE';
var $first = true;
var $use_loop = false;
var $transparent = false;
var $use_global_in = false;
var $x = 0;
var $y = 0;
var $ch = 0;
var $fin = 0;
var $fout = '';
var $loop = 0;
var $delay = 0;
var $width = 0;
var $height = 0;
var $trans1 = 255;
var $trans2 = 255;
var $trans3 = 255;
var $disposal = 2;
var $out_color_table_size = 0;
var $local_color_table_flag = 0;
var $global_color_table_size = 0;
var $out_color_table_sizecode = 0;
var $global_color_table_sizecode= 0;
var $gif = array(0x47, 0x49, 0x46);
var $buffer = array();
var $local_in = array();
var $global_in = array();
var $global_out = array();
var $logical_screen_descriptor = array();
function GifMerge($images, $t1, $t2, $t3, $loop, $dl, $xpos, $ypos, $model) {
if($model) {
$this->mod = $model;
}
if($loop > -1) {
$this->loop = floor($loop - 1);
$this->use_loop = true;
}
if($t1 > -1 && $t2 > -1 && $t3 > -1) {
$this->trans1 = $t1;
$this->trans2 = $t2;
$this->trans3 = $t3;
$this->transparent = true;
}
for($i = 0; $i $dl[$i] ? $this->delay = $dl[$i] : $this->delay = $this->dly;
$xpos[$i] ? $this->x = $xpos[$i] : $this->x = 0;
$ypos[$i] ? $this->y = $ypos[$i] : $this->y = 0;
$this->start_gifmerge_process($images[$i]);
}
$this->fout .= "/x3b";
}
function start_gifmerge_process($fp) {
if($this->mod == 'C_FILE') {
if(!$this->fin = fopen($fp, 'rb')) {
return;
}
} elseif($this->mod == 'C_MEMORY') {
$this->ch = 0;
$this->fin = $fp;
}
$this->getbytes(6);
if(!$this->arrcmp($this->buffer, $this->gif, 3)) {
return;
}
$this->getbytes(7);
if($this->first) $this->logical_screen_descriptor = $this->buffer;
$this->global_color_table_sizecode = $this->buffer[4] & 0x07;
$this->global_color_table_size = 2 global_color_table_sizecode;
if($this->buffer[4] & 0x80) {
$this->getbytes((3 * $this->global_color_table_size));
for($i = 0; $i global_color_table_size)); $i++) {
$this->global_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $this->global_color_table_size;
$out_color_table_sizecode = $this->global_color_table_sizecode;
$this->global_out = $this->global_in;
}
if($this->global_color_table_size != $this->out_color_table_size || $this->arrcmp($this->global_out, $this->global_in, (3 * $this->global_color_table_size))) {
$this->use_global_in = true;
}
}
for($loop = true; $loop;) {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0x21:
$this->read_extension();
break;
case 0x2c:
$this->read_image_descriptor();
break;
case 0x3b:
$loop = false;
break;
default:
$loop = false;
}
}
if($this->mod == 'C_FILE') {
fclose($this->fin);
}
}
function read_image_descriptor() {
$this->getbytes(9);
$head = $this->buffer;
$this->local_color_table_flag = ($this->buffer[8] & 0x80) ? true : false;
if($this->local_color_table_flag) {
$sizecode = $this->buffer[8] & 0x07;
$size = 2 $this->getbytes(3 * $size);
for($i = 0; $i $this->local_in[$i] = $this->buffer[$i];
}
if($this->out_color_table_size == 0) {
$this->out_color_table_size = $size;
$out_color_table_sizecode = $sizecode;
for($i = 0; $i {
$this->global_out[$i] = $this->local_in[$i];
}
}
}
if($this->first) {
$this->first = false;
$this->fout .= "/x47/x49/x46/x38/x39/x61";
if($this->width && $this->height) {
$this->logical_screen_descriptor[0] = $this->width & 0xFF;
$this->logical_screen_descriptor[1] = ($this->width & 0xFF00) >> 8;
$this->logical_screen_descriptor[2] = $this->height & 0xFF;
$this->logical_screen_descriptor[3] = ($this->height & 0xFF00) >> 8;
}
$this->logical_screen_descriptor[4] |= 0x80;
$this->logical_screen_descriptor[5] &= 0xF0;
$this->logical_screen_descriptor[6] |= $this->out_color_table_sizecode;
$this->putbytes($this->logical_screen_descriptor, 7);
$this->putbytes($this->global_out, ($this->out_color_table_size * 3));
if($this->use_loop) {
$ns[0] = 0x21;
$ns[1] = 0xFF;
$ns[2] = 0x0B;
$ns[3] = 0x4e;
$ns[4] = 0x45;
$ns[5] = 0x54;
$ns[6] = 0x53;
$ns[7] = 0x43;
$ns[8] = 0x41;
$ns[9] = 0x50;
$ns[10] = 0x45;
$ns[11] = 0x32;
$ns[12] = 0x2e;
$ns[13] = 0x30;
$ns[14] = 0x03;
$ns[15] = 0x01;
$ns[16] = $this->loop & 255;
$ns[17] = $this->loop >> 8;
$ns[18] = 0x00;
$this->putbytes($ns, 19);
}
}
if($this->use_global_in) {
$outtable = $this->global_in;
$outsize = $this->global_color_table_size;
$outsizecode = $this->global_color_table_sizecode;
} else {
$outtable = $this->global_out;
$outsize = $this->out_color_table_size;
}
if($this->local_color_table_flag) {
if($size == $this->out_color_table_size && !$this->arrcmp($this->local_in, $this->global_out, $size)) {
$outtable = $global_out;
$outsize = $this->out_color_table_size;
} else {
$outtable = $this->local_in;
$outsize = $size;
$outsizecode = $sizecode;
}
}
$use_trans = false;
if($this->transparent) {
for($i = 0; $i if($outtable[3 * $i] == $this->trans1 && $outtable [3 * $i + 1] == $this->trans2 && $outtable [3 * $i + 2] == $this->trans3) {
break;
}
}
if($i $transindex = $i;
$use_trans = true;
}
}
if($this->delay || $use_trans) {
$this->buffer[0] = 0x21;
$this->buffer[1] = 0xf9;
$this->buffer[2] = 0x04;
$this->buffer[3] = ($this->disposal $this->buffer[4] = $this->delay & 0xff;
$this->buffer[5] = ($this->delay & 0xff00) >> 8;
$this->buffer[6] = $use_trans ? $transindex : 0;
$this->buffer[7] = 0x00;
$this->putbytes($this->buffer,8);
}
$this->buffer[0] = 0x2c;
$this->putbytes($this->buffer,1);
$head[0] = $this->x & 0xff;
$head[1] = ($this->x & 0xff00) >> 8;
$head[2] = $this->y & 0xff;
$head[3] = ($this->y & 0xff00) >> 8;
$head[8] &= 0x40;
if($outtable != $this->global_out) {
$head[8] |= 0x80;
$head[8] |= $outsizecode;
}
$this->putbytes($head,9);
if($outtable != $this->global_out) {
$this->putbytes($outtable, (3 * $outsize));
}
$this->getbytes(1);
$this->putbytes($this->buffer,1);
for(;;) {
$this->getbytes(1);
$this->putbytes($this->buffer,1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
$this->putbytes($this->buffer, $u);
}
}
function read_extension() {
$this->getbytes(1);
switch($this->buffer[0]) {
case 0xf9:
$this->getbytes(6);
break;
case 0xfe:
for(;;) {
$this->getbytes(1);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0x01:
$this->getbytes(13);
for(;;) {
$this->getbytes(0);
if(($u = $this->buffer[0]) == 0) {
break;
}
$this->getbytes($u);
}
break;
case 0xff:
$this->getbytes(9);
$this->getbytes(3);
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
break;
default:
for(;;) {
$this->getbytes(1);
if(!$this->buffer[0]) {
break;
}
$this->getbytes($this->buffer[0]);
}
}
}
function arrcmp($b, $s, $l) {
for($i = 0; $i if($s{$i} != $b{$i}) {
return false;
}
}
return true;
}
function getbytes($l) {
for($i = 0; $i if($this->mod == 'C_FILE') {
$bin = unpack('C*', fread($this->fin, 1));
$this->buffer[$i] = $bin[1];
} elseif($this->mod == 'C_MEMORY') {
$bin = unpack('C*', substr($this->fin, $this->ch, 1));
$this->buffer[$i] = $bin[1];
$this->ch++;
}
}
return $this->buffer;
}
function putbytes($s, $l) {
for($i = 0; $i $this->fout .= pack('C*', $s[$i]);
}
}
function getAnimation() {
return $this->fout;
}
}
?>
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
1 몇 달 전
By DDD
R.E.P.O. 최고의 그래픽 설정
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
1 몇 주 전
By DDD
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7407
15


자바 튜토리얼
1630
14


Cakephp 튜토리얼
1358
52


라라벨 튜토리얼
1268
25


PHP 튜토리얼
1218
29



이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

CakePHP에서 데이터베이스 작업은 매우 쉽습니다. 이번 장에서는 CRUD(생성, 읽기, 업데이트, 삭제) 작업을 이해하겠습니다.
