简体   繁体   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);

?>

Is there any way to resize the .png image by code to a static 50x50px value? 有没有办法通过代码将.png图像调整为静态50x50px值? Thanks 谢谢

I would use imagecopyresampled 我会使用imagecopyresampled

It can used like this: 它可以像这样使用:

$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