gpt4 book ai didi

php - 调整 png/jpeg 图像的大小

转载 作者:可可西里 更新时间:2023-11-01 01:06:16 27 4
gpt4 key购买 nike

<?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());

关于php - 调整 png/jpeg 图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10263171/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com