将文件夹中的文件显示为缩略图 php
我正在尝试调整从文件夹导入的一些图像的大小。如果只将真实图片显示为缩略图也没关系,因为文件的大小不会比 500kb 大很多,
有没有办法使图像成为可点击的图像?我用谷歌搜索了它,但似乎找不到对我有帮助的解决方案。
这是从文件夹中读取的代码
$files = glob("uploads/*.*");
for ($i=1; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" alt="random image">'." ";
}
Im trying to rezise some images that are imported from a folder. It doesent matter if it only show the realpicture as a thumbnail since the size of the file wont be much larger than 500kb,
Is there a way I can make the images as clickable images ? I have google it , but cant seem to find a solution that helps me.
This is the code that reads from the folder
$files = glob("uploads/*.*");
for ($i=1; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" alt="random image">'." ";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定如何使用 PHP 实际调整图像大小以减小文件大小,但要使浏览器以较小的“缩略图”大小呈现它们,只需向推出的图像添加 CSS 类属性即可。像这样的事情:
然后,只需将 img.thumb 类的一些 CSS 添加到文档顶部,或者添加到 CSS 的其余部分的任何位置:
如果您希望图像可点击(大概链接到全尺寸图像) ),只需在回显文档时将锚标记包裹在 img 标记周围即可。像这样的事情:
I'm not sure how to actually resize the images with PHP to reduce the file size, but to make the browser render them at a small 'thumbnail' size just add a CSS class attribute to the images that are pushed out. Something like this:
Then, just add some CSS for the img.thumb class to the top of your document, or wherever you have the rest of your CSS:
If you want the images to by clickable (presumably linking to the full-size image), just wrap anchor tags around your img tags when echo'ing to the document. Something like this:
clickable 意味着链接
,或者你可以使用 javascript 来完成,但这更容易
clickable means links
or you can do it with javascript, but this is easier