2012-04-21 114 views
3
<?php 

header('Content-type:image/gif'); 
header('Content-Disposition: attachment; filename="animated.gif"'); 

require_once('GIFEncoder.class.php'); 

$image = imagecreatefrompng('source01.png'); 

$width = 50; 
$height = 50; 
$new_image = imagecreatetruecolor($width, $height); 
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, 200, 115); 

$text_color = imagecolorallocate($image, 50, 50, 50); 
imagestring($image, 5, 5, 5, '', $text_color); 

/* $imageMagick = new Imagick($image); 
$imageMagick->adaptiveResizeImage(50,50); */ 

ob_start(); 
imagegif($image); 
$frames[]=ob_get_contents(); 
$framed[]=40; 
ob_end_clean(); 


$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin'); 
echo $gif->GetAnimation(); 

//$fp = fopen('animegif.gif', 'w'); 
//fwrite($fp, $gif->GetAnimation()); 
//fclose($fp); 

?> 

是否有任何方法通過代碼將.png圖像調整爲靜態50x50px值?由於調整大小png/jpeg圖像

回答

4

我會用imagecopyresampled

它可以像這樣使用:

$width = 50; 
$height = 50; 
$new_image = imagecreatetruecolor($width, $height); 
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image.getWidth)=(), $image.getHeight()); 
+0

你的榜樣更新,但克被壓縮的gif(基於.png)保持其原始大小。我錯過了什麼? :-) – Johan 2012-04-21 21:46:03

+0

你沒有使用$ new_image。 – Mads 2012-04-21 21:49:37

+1

* facepalm *,謝謝 – Johan 2012-04-21 21:51:07