【问题标题】:resize png/jpeg image调整 png/jpeg 图像的大小
【发布时间】:2012-04-22 05:45:24
【问题描述】:
<?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 值?谢谢

【问题讨论】:

    标签: php


    【解决方案1】:

    我会使用imagecopyresampled

    可以这样使用:

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

    【讨论】:

    • 已使用您的示例进行了更新,但生成的 gif(基于 .png)仍保持其原始大小。我错过了什么? :-)
    • 你没有使用 $new_image。
    【解决方案2】:

    【讨论】:

    • 我已经尝试了最后一个链接。当我使用它时(请参阅注释行),我会从中得到一个不可读的 gif:/
    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 2012-07-30
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多