>  기사  >  백엔드 개발  >  매우 실용적인 수업인 PHP는 gif 이미지의 크기를 조정합니다!

매우 실용적인 수업인 PHP는 gif 이미지의 크기를 조정합니다!

WBOY
WBOY원래의
2016-07-25 08:49:171243검색
} }
이 클래스는 GIF 형식의 동적 파일을 조정할 수 있습니다. 동적 사진 프레임 파일을 임시 디렉토리에 추출합니다. 이미지 크기를 조정하고 애니메이션 GIF 형식의 새 파일로 추출하여 재구성합니다.

@红豆不허용 gif 이미지 업로드
효과 보기: http://www.codepearl.com/files/187.html 매우 실용적인 수업인 PHP는 gif 이미지의 크기를 조정합니다!
  1. //http://www.codepearl.com
  2. require_once "gifresizer.php"
  3. $gr = new gifresizer;
  4. $gr->temp_dir = "codepearl";
  5. $gr->resize("codepearl.gif","codepearl_resize.gif",
  6. ?>
코드 복사
  1. /**
  2. * http://www.codepearl.com
  3. * 애니메이션 GIF 파일 크기 조정
  4. *
  5. * ///중요 참고: 스크립트에는 모든 프레임을 추출해야 하는 임시 디렉터리가 필요합니다.
  6. * 권한 수준이 777인 디렉터리를 생성하고 아래 $temp_dir 변수에 경로를 씁니다.
  7. *
  8. * 기본 디렉터리는 "frames"입니다.
  9. */
  10. 클래스 gifresizer {
  11. public $temp_dir = "frames";
  12. private $pointer = 0;
  13. private $index = 0;
  14. 프라이빗 $globaldata = array();
  15. 프라이빗 $imagedata = array();
  16. 프라이빗 $imageinfo = array();
  17. 프라이빗 $handle = 0;
  18. 프라이빗 $orgvars = array();
  19. private $encdata = array();
  20. private $parsedfiles = array();
  21. private $originalwidth = 0;
  22. private $originalheight = 0;
  23. private $ wr,$hr;
  24. private $props = array();
  25. private $decoding = false;
  26. /**
  27. * 클래스의 공개 부분
  28. *
  29. * @orgfile - 원본 파일 경로
  30. * @newfile - 경로가 포함된 새 파일 이름
  31. * @width - 원하는 이미지 너비
  32. * @height - 원하는 이미지 높이
  33. */
  34. 함수 resize($orgfile,$newfile ,$width,$height){
  35. $this->decode($orgfile);
  36. $this->wr=$width/$this->originalwidth;
  37. $this-> hr=$height/$this->originalheight;
  38. $this->resizeframes();
  39. $this->encode($newfile,$width,$height);
  40. $this- >clearframes();
  41. }
  42. /**
  43. * GIF 디코더 기능.
  44. * GIF 애니메이션을 단일 프레임으로 파싱합니다.
  45. */
  46. 개인 함수 decode($filename){
  47. $this->decoding = true;
  48. $this->clearvariables();
  49. $this->loadfile($filename);
  50. $this->get_gif_header();
  51. $this->get_graphics_extension(0) ;
  52. $this->get_application_data();
  53. $this->get_application_data();
  54. $this->get_image_block(0);
  55. $this->get_graphics_extension(1) ;
  56. $this->get_comment_data();
  57. $this->get_application_data();
  58. $this->get_image_block(1);
  59. while(!$this->checkbyte (0x3b) && !$this->checkEOF()){
  60. $this->get_comment_data(1);
  61. $this->get_graphics_extension(2);
  62. $this->get_image_block (2);
  63. }
  64. $this->writeframes(time());
  65. $this->closefile();
  66. $this->decoding = false;
  67. }
  68. /**
  69. * GIF 인코더 기능.
  70. * 구문 분석된 GIF 프레임을 하나의 애니메이션으로 결합합니다.
  71. */
  72. 개인 함수 인코딩($ new_filename,$newwidth,$newheight){
  73. $mystring = "";
  74. $this->pointer = 0;
  75. $this->imagedata = array();
  76. $this- >imageinfo = array();
  77. $this->handle = 0;
  78. $this->index=0;
  79. $k=0;
  80. foreach($this ->파일을 $imagepart로 구문 분석함){
  81. $this->loadfile($imagepart);
  82. $this->get_gif_header();
  83. $this->get_application_data();
  84. $this->get_comment_data();
  85. $this->get_graphics_extension(0);
  86. $this->get_image_block(0);
  87. //투명 색상 인덱스 및 색상 가져오기
  88. if(isset($this->encdata[$this->index-1]))
  89. $gxdata = $this->encdata[$this->index-1]["graphicsextension" ];
  90. else
  91. $gxdata = null;
  92. $ghdata = $this->imageinfo["gifheader"];
  93. $trcolor = "";
  94. $hastransparency=($gxdata [3]&&1==1);
  95. if($hastransparency){
  96. $trcx = ord($gxdata[6]);
  97. $trcolor = substr($ghdata,13 $trcx *3,3);
  98. }
  99. //이미지 데이터에 대한 전역 색상표;
  100. $this->transfercolortable($this->imageinfo["gifheader"],$this->imagedata[$this->index -1]["이미지데이터"]);
  101. $imageblock = &$this->imagedata[$this->index-1]["imagedata"];
  102. //투명도가 존재하는 경우 투명도 지수 전송
  103. if ($hastransparency){
  104. $haslocalcolortable = ((ord($imageblock[9])&128)==128);
  105. if($haslocalcolortable){
  106. //로컬 테이블이 존재합니다. 경계를 결정하고 찾아보세요.
  107. $tablesize=(pow(2,(ord($imageblock[9])&7) 1)*3) 10;
  108. $this->orgvars[$this-> ;index-1]["transparent_color_index"] =
  109. ((strrpos(substr($this->imagedata[$this->index-1]["imagedata"],0,$tablesize),$trcolor )-10)/3);
  110. }else{
  111. //로컬 테이블이 없습니다. 글로벌 테이블을 살펴보세요.
  112. $tablesize=(pow(2,(ord($gxdata[10])&7) 1)*3) 10 ;
  113. $this->orgvars[$this->index-1]["transparent_color_index"] =
  114. ((strrpos(substr($ghdata,0,$tablesize),$trcolor)-10) /3);
  115. }
  116. }
  117. //원래 지연 시간, 투명 인덱스 및 삭제 값을 그래픽 확장에 적용
  118. if(!$this->imagedata[$this-> index-1]["graphicsextension"]) $this->imagedata[$this->index-1]["graphicsextension"] = chr(0x21).chr(0xf9).chr(0x04).chr(0x00 ).chr(0x00).chr(0x00).chr(0x00).chr(0x00);
  119. $imagedata = &$this->imagedata[$this->index-1][" graphicextension"];
  120. $imagedata[3] = chr((ord($imagedata[3]) & 0xE3) | ($this->orgvars[$this->index-1][" 처분 방법"] << 2));
  121. $imagedata[4] = chr(($this->orgvars[$this->index-1]["delay_time"] % 256));
  122. $imagedata[5] = chr(floor($this->orgvars[$this->index-1]["delay_time"] / 256));
  123. if($hastransparency){
  124. $imagedata[6] = chr($this->orgvars[$this->index-1]["transparent_color_index"]);
  125. }
  126. $imagedata[3] = chr(ord($imagedata [3])|$hastransparency);
  127. //계산된 왼쪽 및 위쪽 오프셋 적용
  128. $imageblock[1] = chr(round(($this->orgvars[$this->index -1]["offset_left"]*$this->wr) % 256));
  129. $imageblock[2] = chr(floor(($this->orgvars[$this->index-1 ]["offset_left"]*$this->wr) / 256));
  130. $imageblock[3] = chr(round(($this->orgvars[$this->index-1][ "offset_top"]*$this->hr) % 256));
  131. $imageblock[4] = chr(floor(($this->orgvars[$this->index-1]["offset_top "]*$this->hr) / 256));
  132. if($this->index==1){
  133. if(!isset($this->imageinfo["applicationdata"]) || !$this->imageinfo[" applicationdata"])
  134. $this->imageinfo["applicationdata"]=chr(0x21).chr(0xff).chr(0x0b)."NETSCAPE2.0".chr(0x03).chr(0x01). chr(0x00).chr(0x00).chr(0x00);
  135. if(!isset($this->imageinfo["commentdata"]) || !$this->imageinfo["commentdata"])
  136. $this->imageinfo["commentdata"] = chr(0x21).chr(0xfe).chr(0x10)."PHPGIFRESIZER1.0".chr(0);
  137. $mystring .= $this ->orgvars["gifheader"]. $this->imageinfo["applicationdata"].$this->imageinfo["commentdata"];
  138. if(isset($this->orgvars["hasgx_type_0"]) && $this->orgvars ["hasgx_type_0"]) $mystring .= $this->globaldata["graphicsextension_0"];
  139. if(isset($this->orgvars["hasgx_type_1"]) && $this->orgvars[" hasgx_type_1"]) $mystring .= $this->globaldata["graphicsextension"];
  140. }
  141. $mystring .= $imagedata . $imageblock;
  142. $k ;
  143. $this->closefile();
  144. }
  145. $mystring .= chr(0x3b);
  146. //對 gif 標題套用新的寬度和高度
  147. $mystring[6] = chr($newwidth % 256);
  148. $mystring[7] = chr(floor($newwidth / 256) ));
  149. $mystring[8] = chr($newheight % 256);
  150. $mystring[9] = chr(floor($newheight / 256));
  151. $mystring[11] = $ this->orgvars["background_color"];
  152. //if(file_exists($new_filename)){unlink($new_filename);}
  153. file_put_contents($new_filename,$mystring);
  154. }
  155. /**
  156. * 變數重設功能
  157. * 如果一個實例被多次使用,則需要它。相信我。
  158. */
  159. 血管函數clearvariables(){
  160. $this->pointer = 0;
  161. $this->index = 0;
  162. $this - >imagedata = array();
  163. $this->imageinfo = array();
  164. $this->handle = 0;
  165. $this->parsedfiles = array();
  166. }
  167. /**
  168. * 清除幀功能
  169. * 用於編碼後刪除幀。
  170. */
  171. 牛皮函數clearframes () {
  172. foreach($this->parsedfiles as $temp_frame){
  173. unlink($temp_frame);
  174. }
  175. }
  176. /**
  177. * 幀寫入器
  178. * 將 GIF 幀寫入檔案。
  179. */
  180. 私有函數writeframes($prepend){
  181. for($i=0;$iimagedata);$i ){
  182. file_put_contents($this->temp_dir. "/frame_". $prepend."_".str_pad($i,2,"0",STR_PAD_LEFT).".gif",$this->imageinfo["gifheader"].$this->imagedata[ $i]["graphicsextension" ].$this->imagedata[$i]["imagedata"].chr(0x3b));
  183. $this->parsedfiles[]=$this->temp_dir。 ".str_pad($i,2,"0",STR_PAD_LEFT).".gif";
  184. }
  185. }
  186. /**
  187. * 調色盤傳輸裝置
  188. * 將全域色表(GCT)從影格傳送到動畫中的局部色表。
  189. */
  190. 私有函數transfercolortable( $src,&$dst){
  191. //src為gif頭,dst為圖像資料塊
  192. //如果全域色表存在,則傳輸
  193. if ((ord($src[10]) &128)==128){
  194. //Gif 標題全域顏色表長度
  195. $ghctl = pow(2,$this->readbits(ord($src[ 10]),5,3) 1)* 3;
  196. //從gif頭中剪下全域顏色表
  197. $ghgct = substr($src,13,$ghctl);
  198. //檢查圖片區塊顏色表長度
  199. if(( ord ($dst[9])&128)==128){
  200. //影像資料包含色表。最後一個顏色表長度,以便我們可以中斷虛擬顏色表
  201. $idctl = pow(2,$this ->readbits(ord($dst[9]),5,3) 1)*3;
  202. //設定顏色表標誌與長度
  203. $dst[9] = chr(ord($dst[9]) | (0x80 | (log($ghctl/3,2)-1)));
  204. //注入顏色表
  205. $dst = substr($dst,0,10).$ghgct. substr($dst,-1*strlen($dst) 10);
  206. }
  207. }else{
  208. //全域顏色表不存在。 >
  209. /**
  210. * GIF 解析器函數。
  211. * 以下函數是解析器的主要結構組件。
  212. */
  213. private function get_gif_header(){
  214. $this->p_forward(10);
  215. if ($this->readbits(($mybyte=$this ->readbyte_int()),0,1)==1){
  216. $this->p_forward(2);
  217. $this->p_forward(pow(2,$this->readbits($mybyte, 5,3) 1)*3);
  218. }else{
  219. $this->p_forward(2);
  220. }
  221. $this->imageinfo["gifheader"]=$ this->datapart(0,$this->指針);
  222. if($this->解碼){
  223. $this->orgvars["gifheader"]=$this->imageinfo["gifheader"] ;
  224. $this->originalwidth = ord($this->orgvars["gifheader"][ 7])*256 ord($this->orgvars["gifheader"][6]);
  225. $this ->originalheight = ord($this->orgvars["gifheader"][9]) *256 ord($this->orgvars["gifheader"][8]);
  226. $this->orgvars["background_color "]=$this->orgvars["gifheader"][11];
  227. }
  228. }
  229. //--------------------------------------------- ----------- ----------- ----------
  230. private function get_application_data(){
  231. $startdata = $this- >readbyte(2);
  232. if( $startdata==chr(0x21).chr (0xff)){
  233. $start = $this->pointer - 2;
  234. $this->p_forward($ this->readbyte_int());
  235. $this->read_data_stream( $this->readbyte_int());
  236. $this->imageinfo["applicationdata"] = $this->datapart($start,$ this->pointer-$start);
  237. } else{
  238. $this->p_rewind(2);
  239. }
  240. }
  241. //---------- -------------- --- ---------------------------------
  242. private function get_comment_data(){
  243. $startdata = $this ->readbyte(2);
  244. if($startdata==chr(0x21).chr(0xfe)){
  245. $start =chr(0x21).chr(0xfe)){
  246. $start = $this->指標- 2;
  247. $this- > ;read_data_stream($this->readbyte_int());
  248. $this->imageinfo["commentdata"] = $this->datapart($start, $this->pointer-$start);
  249. } else{
  250. $this->p_rewind(2);
  251. }
  252. }
  253. //--------- ---------- ---- ------------------------------------ --------------------
  254. 創傷函數 get_graphics_extension ($type){
  255. $startdata = $this->readbyte(2);
  256. if ($startdata==chr(0x21).chr(0xf9)){
  257. $start = $this->指標- 2;
  258. $this->p_forward($this->readbyte_int());
  259. $this->p_forward(1);
  260. if($type==2){
  261. $ this-> ;imagedata[$this->index]["graphicsextension"] = $this->datapart( $start,$this->pointer-$start);
  262. }else if($type==1) {
  263. $this->orgvars["hasgx_type_1"] = 1;
  264. $this-> globaldata["graphicsextension"] = $this->datapart($start,$this->pointer- $start);
  265. }else if($type==0 && $this->decoding==false){
  266. $this->encda​​[$this->index]["graphicsextension"] = $this- >datapart($start,$this->指標-$start);
  267. }else if ($type==0 && $this->decoding==true){
  268. $this->orgvars["hasgx_type_0 "] = 1;
  269. $this->globaldata["graphicsextension_0"] = $this- >datapart($start,$this->pointer-$start);
  270. }
  271. }else{
  272. $this->p_rewind(2);
  273. }
  274. }
  275. / /---------------- ------------ --------------------- -------------------------------
  276. 解剖函數get_image_block($type) {
  277. if($this- >checkbyte(0x2c)){
  278. $start = $this->pointer;
  279. $this->p_forward(9);
  280. if($this ->readbits (($mybyte=$this-> readbyte_int()),0,1)==1){
  281. $this->p_forward(pow(2,$this->readbits($mybyte,5,3) 1 )*3);
  282. }
  283. $this->p_forward(1);
  284. $this->read_data_stream($this->readbyte_int());
  285. $this->imagedata[$this ->index]["imagedata"] = $this->datapart($start,$this->pointer-$start);
  286. if ($type==0){
  287. $this- >orgvars["hasgx_type_0"] = 0 ;
  288. if(isset($this->globaldata["graphicsextension_0"]))
  289. $this ->imagedata[$this->index]["graphicsextension"]= $this->globaldata["graphicsextension_0" ];
  290. else
  291. $this->imagedata[$this->index ]["graphicsextension"]=null;
  292. unset($this->globaldata[" GraphicsExtension_0"]);
  293. } elseif($type==1){
  294. if(isset($this->orgvars["hasgx_type_1"]) && $this->orgvars["hasgx_type_1"]==1 ){
  295. $this-> orgvars["hasgx_type_1"] = 0;
  296. $this-> ;imagedata[$this->index]["graphicsextension"]=$this->globaldata["graphicsextension"] ;
  297. unset($this- >globaldata["graphicsextension"]); }else{
  298. $this->orgvars["hasgx_type_0"] = 0;
  299. $this->imagedata[$this->index]["graphicsextension"]=$this->globaldata[" GraphicsExtension_0"];
  300. 取消設定($this->globaldata["graphicsextension_0"]);
  301. }
  302. }
  303. $this->parse_image_data();
  304. $this ->index ;
  305. }
  306. }
  307. //---------------------------- ------- -------------------
  308. 樹枝函數parse_image_data(){
  309. $this->imagedata[$this->; 索引]["disposal_method"] = $this->get_imagedata_bit("ext",3,3,3);
  310. $this->imagedata[$this->index]["user_input_flag"] = $this->get_imagedata_bit("ext",3, 6,1);
  311. $this->imagedata[$this->index]["transparent_color_flag"] = $this->get_imagedata_bit("ext" ,3,7,1);
  312. $this-> imagedata[$this->index]["delay_time"] = $this->dualbyteval($this->get_imagedata_byte("ext",4 ,2));
  313. $this->imagedata[$this->index ]["transparent_color_index"] = ord($this->get_imagedata_byte("ext",6,1));
  314. $this->imagedata[$this->index]["offset_left"] = $this-> Dualbyteval($this->get_imagedata_byte("dat",1,2));
  315. $this->imagedata[$this->index]["offset_top"] = $this->dualbyteval($this->get_imagedata_byte ("dat",3,2));
  316. $this->imagedata [$this->index]["width"] = $this->dualbyteval($this->get_imagedata_byte("dat",5, 2));
  317. $this->imagedata[$this ->index]["height"] = $this->dualbyteval($this->get_imagedata_byte("dat",7,2));
  318. $這個->影像資料[$這個->; index]["local_color_table_flag"] = $this->get_imagedata_bit("dat",9,0,1);
  319. $this->imagedata[$this->index]["interlace_flag"] = $this-> get_imagedata_bit("dat",9,1,1);
  320. $this->imagedata[$this->index]["sort_flag"] = $this->get_imagedata_bit("dat" ,9,2,1) ;
  321. $this->imagedata[$this->index]["color_table_size"] = pow(2,$this->get_imagedata_bit("dat",9,5, 3) 1)*3;
  322. $this->imagedata[$this->index]["color_table"] = substr($this->imagedata[$this->index]["imagedata"],10,$this->imagedata[$this-> index]["color_table_size"]);
  323. $this->imagedata[$this->index]["lzw_code_size"] = ord( $this->get_imagedata_byte("dat",10,1));
  324. if($this->解碼){
  325. $this->orgvars[$this->index]["transparent_color_flag "] = $this->imagedata[$this->index]["transparent_color_flag"];
  326. $this->orgvars[$this->index]["transparent_color_index"] = $this-> ;imagedata[$this->index]["transparent_color_index"];
  327. $this->orgvars[$this ->index]["delay_time"] = $this->imagedata[$this-> ;index]["delay_time"];
  328. $this->orgvars[$this->index]["disposal_method"] = $this->imagedata[$this->index]["disposal_method" ];
  329. $this->orgvars[$this->index]["offset_left"] = $this->imagedata[$this->index ]["offset_left"];
  330. $this ->orgvars[$this->index]["offset_top"] = $this->imagedata[$this->index]["offset_top"];
  331. }
  332. }
  333. / /----------------------------------------- --------------- -------- ------
  334. private function get_imagedata_byte($type,$start,$length){
  335. if ($type=="ext")
  336. return substr( $this->imagedata[$this->index]["graphicsextension"],$start,$length);
  337. elseif($type==" dat")
  338. return substr($this->imagedata[ $this->;索引]["imagedata"],$start,$length);
  339. }
  340. //--------------------------------------------- ----------- ----------- ----------
  341. private function get_imagedata_bit($type,$byteindex,$bitstart,$bitlength ){
  342. if($type== "ext")
  343. return $this->readbits(ord(substr($this->imagedata[$this->index]["graphicsextension"],$byteindex, 1)),$bitstart,$bitlength);
  344. elseif($type= ="dat")
  345. return $this->readbits(ord(substr($this->imagedata[$this->index] ["imagedata"],$byteindex,1) ),$bitstart, $bitlength);
  346. }
  347. //--------------------- ----------- -------- ------------------
  348. 臍函數dualbyteval($s){
  349. $i = ord($s[1] )*256 ord($s[ 0]);
  350. return $i;
  351. }
  352. //----------- - 輔助函數-------- -------- -----
  353. 私有函數read_data_stream($first_length){
  354. $this->p_forward($first_length);
  355. $length=$this->readbyte_int() ;
  356. if( $length!=0) {
  357. while($length!=0){
  358. $this->p_forward($length);
  359. $length=$this->readbyte_int( );
  360. }
  361. }
  362. 回傳true;
  363. }
  364. //-------------- -------------------------- --------------- --------- -----------------
  365. 私有函數loadfile($filename ){
  366. $this->handle = fopen($檔名,"rb");
  367. $this->pointer = 0;
  368. }
  369. //-------- ------------------------ ------------------------
  370. private function closefile(){
  371. fclose($this->handle);
  372. $this ->handle=0;
  373. }
  374. //------------ -------------- --------- ----------------------
  375. 私有函數readbyte($byte_count){
  376. $data = fread( $this->handle,$byte_count) ;
  377. $this->pointer = $byte_count;
  378. return $data;
  379. }
  380. //------------ --------- --------------------------- ----------------------
  381. 原生函數readbyte_int(){
  382. $data = fread($this->handle,1);
  383. $this->指標;
  384. return ord($data);
  385. }
  386. / /------------------------ ----------------------- -- ------
  387. 私有函式readbits($byte,$start,$length){
  388. $bin = str_pad(decbin($byte),8,"0",STR_PAD_LEFT);
  389. $ data = substr($bin,$start,$length);
  390. return bindec($data);
  391. }
  392. //--------------- ----------------------------------------- --------- ----
  393. 蠟燭函數p_rewind($length){
  394. $this->pointer-=$length;
  395. fseek($this->handle,$this ->指針);
  396. }
  397. //-------- ---------------------------- --------- ----------------------
  398. 私有函數p_forward($length){
  399. $this->指標=$length;
  400. fseek( $this->句柄,$this->指標);
  401. }
  402. // ------------------- --------- ---------------------- -----
  403. private function datapart($start,$length){
  404. fseek($this-> handle,$start);
  405. $data = fread($this->handle, $length);
  406. fseek($this->句柄,$this->指針) ;
  407. return $data;
  408. }
  409. //------------ -------------------------- ---- -------------------------------
  410. 蠟燭函數checkbyte($byte){
  411. if (fgetc($ this->handle)==chr($byte)){
  412. fseek($this->handle,$this->pointer);
  413. return true;
  414. }else{
  415. fseek($ this->句柄,$this->指標);
  416. return false;
  417. }
  418. }
  419. // --------------- ---- ------------------------------- -----
  420. 陰道函數checkEOF(){
  421. if( fgetc($this->handle)===false){
  422. return true;
  423. }else{
  424. fseek ($this->句柄,$this->指針);
  425. return false;
  426. }
  427. }
  428. //---------------------------- --------- --------- ----------------------------------
  429. /**
  430. * 偵錯功能。
  431. * 將 GIF 動畫解析為單幀。
  432. * /
  433. 私有函數debug($string){
  434. echo "
    ";
  435. for($i=0;$i echo str_pad(dechex(ord($ string[$i])),2,"0",STR_PAD_LEFT)。
  436. //--------------------------------------------- ----------- ----------- ----------
  437. private function debuglen($var,$len){
  438. echo "
    ";
  439. for( $i=0;$i echo str_pad(dechex(ord($var[$i])),2,"0" ,STR_PAD_LEFT)。 " ";
  440. }
  441. echo "";
  442. }
  443. //----------------------- - ------------- ---------------------------------
  444. 原生函數debugstream($length){
  445. $this->debug($this->datapart($this->pointer,$length));
  446. }
  447. //------- - --------- ---------------------------------------- ------------- --------
  448. /**
  449. * GD Resizer Device
  450. * 調整動畫影格的大小
  451. */
  452. 私有函數resizeframes(){
  453. $k=0;
  454. foreach($this->parsedfiles as $img) {
  455. $src = imagecreatefromgif($img);
  456. $sw = $這->imagedata[$k]["width"];
  457. $sh = $this->imagedata[$k][ "高度"];
  458. $nw = round($sw * $this ->wr);
  459. $nh = round($sh * $this- >hr);
  460. $sprite = imagecreatetruecolor($西北,$nh);
  461. $trans = imagecolortransparent($sprite);
  462. imagealphablending($sprite, false);
  463. imagesavealpha($sprite, true);
  464. imagepalettecopy($sprite,$src);
  465. imagefill($sprite,0,0,imagecolortransparent($src));
  466. imagecolortransparent($sprite,imagecolortransparent($src));
  467. imagecopyresized($sprite,$src,0,0,0,0,$nw,$nh,$sw,$sh);
  468. imagegif($sprite,$img);
  469. imagedestroy($sprite);
  470. imagedestroy($src);
  471. $k ;
  472. }
  473. }
  474. }
  475. }
  476. }
  477. }
}
} } }
}
} }
}
}
}
}
}
} } } } } } } } } } } }} > ?>複製程式碼
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.