0

I have a script on my site that displays any image files I add to a certain folder. I use this folder as a depository for any digital art I make. That way I can just save png's from Photoshop or whatever directly to that folder and the will display on the page.

The problem is that the files sizes are too large to be loaded easily, even if they are displaying correctly. The .css class is the image resizer.

Can you resize an image without loading it entirely? I might be understanding this wrong, thanks for your help.

<?php
    $dir = "../endlessdescriptionone/images/";
    $dh = opendir($dir);
    $gallery = array();
    while($filename = readdir($dh)) {
        $filepath = $dir.$filename;

        //pregmatch usedto be ereg
        if (is_file($filepath) and preg_match("/\.png$/",$filename)) {
            $gallery[] = $filepath;
        }
    }
    sort($gallery);

    foreach($gallery as $image) {
        echo"<img src='$image' class='resizesmall'>";
    }
?>
4

3 回答 3

2

查看 phpthumb,它几乎是事实上的缩略图生成器,并提供自动缓存以提高首次加载后的速度。在一个非常基本的级别上,您所要做的就是将图像源标签指向 phpthumb 脚本,并在 GET 字符串中使用所需的宽度、高度和文件位置。

由于 phpthumb 的许可,我还必须为奇怪的场合创建自己的简单缩略图。如果您熟悉 PHP 文档站点,您可以在几个小时内拼凑出自己的缩略图,并在此过程中学到一些东西。

如果做不到这一切,您可以手动执行并上传图像的两个副本,一个大的,一个调整大小的,并且只显示调整大小的那些(即仅在文件名中包含“_thumb”的那些)。

于 2012-01-31T12:22:46.743 回答
1

不,您不能使用 CSS 来降低浏览器加载的图像的实际分辨率。

您可以做的是在 img src 标记中使用另一个脚本,该脚本在输出图像之前加载图像并调整大小。

于 2012-01-31T12:19:08.870 回答
1

常见用途是显示大图像的缩略图(样本),然后在选择时:下载或查看。

您可以直接从 Photoshop 创建缩略图。

于 2012-01-31T12:22:06.743 回答