首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何制作缩略图?

如何制作缩略图?
EN

Stack Overflow用户
提问于 2013-03-18 17:37:05
回答 3查看 114关注 0票数 0

嘿,我有个任务要做个画廊。我的代码现在只显示了图片,但我想为这些图片制作缩略图。

我该怎么做呢?有什么建议吗?

代码语言:javascript
复制
<html>
<head>
<style type="text/css"> 

ul {
    list-style:none;
}

</style>

</head>
<body>
<ul>
<?php
    $imgdir = 'images/';
    $allowed_types = array('png', 'jpg', 'jpeg', 'gif');
    $dimg = opendir($imgdir);
    while($imgfile = readdir($dimg)) {
        if(in_array(strtolower(substr($imgfile, -3)), $allowed_types) or in_array(strtolower(substr($imgfile, -4)), $allowed_types)) {
            $a_img[] = $imgfile; 
        }
    }
    echo "<ul>";

    $totimg = count($a_img);
    for($x=0; $x < $totimg; $x++) {
        echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";
    }
    echo "</ul>";

?>
</ul>
</body>
</html>
EN

回答 3

Stack Overflow用户

发布于 2013-03-18 17:40:20

尝试使用Imagine库。它是一个功能强大的图像处理库。

票数 0
EN

Stack Overflow用户

发布于 2013-03-18 17:45:25

此问题/答案将帮助您,并让您了解如何重新调整图像大小。

Image Re-sizing in PHP

票数 0
EN

Stack Overflow用户

发布于 2013-03-18 17:53:39

您可以使用Imagick扩展。

如下所示:

代码语言:javascript
复制
<?php

header('Content-type: image/jpeg');

$image = new Imagick('tc5.jpg');

// If 0 is provided as a width or height parameter,
// aspect ratio is maintained
$image->thumbnailImage(100, 0);

echo $image;

?> 

http://php.net/manual/en/imagick.cropthumbnailimage.php

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15473556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档