簡體   English   中英

調整png / jpeg圖像的大小

[英]resize png/jpeg image

<?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值? 謝謝

我會使用imagecopyresampled

它可以像這樣使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM