简体   繁体   English

PHP-显示来自Mysql的图像的缩略图

[英]PHP - display thumbnails of images from Mysql

I have a table in my mysql db that contains path for images. 我的mysql数据库中有一个表,其中包含图像的路径。 I want to display thumbnails of this images. 我想显示此图像的缩略图。 Can you tell me what is the best solution for that. 你能告诉我什么是最好的解决方案。 This is how i display the full size images from db: 这是我从db显示全尺寸图像的方式:

<?php for($i=1; $i<=5; $i++)
{$query = mysql_query("SELECT * FROM photos WHERE product_id='".$i."'");
$row = mysql_fetch_array($query);
$t="img/";
$file = $t .$row[1];
echo "<li><a href=\"#\"><img src = " . $file . "></a></li>";
} ?>

调整css / html中图像的大小(错误)或制作一个以文件名作为输入的php脚本,然后返回缩小版本作为输出(更好)或将缩略图存储在服务器上(最好)

You should avoid having to resize the images using CSS or HTML. 您应避免使用CSS或HTML调整图像大小。 Before saving the images onto the server, you should use ImageMagick to resize it. 将图像保存到服务器上之前,应使用ImageMagick调整其大小。 Do you really want to store a bunch of 6MB images? 您真的要存储一堆6MB的图像吗? If that's not feasible, then saving the images as is and pointing to the path would suffice. 如果那不可行,则按原样保存图像并指向路径即可。 However, if you end up with hundreds or thousands of images, you'll want to explore a better option. 但是,如果最终得到成百上千张图像,则需要探索一个更好的选择。

I agree with the approach of storing the file path (instead of the binary file itself). 我同意存储文件路径(而不是二进制文件本身)的方法。

So your question is "how do you create a thumbnail?" 因此,您的问题是“如何创建缩略图?”

The best answer is ImageMagick: 最好的答案是ImageMagick:

http://www.imagemagick.org/ http://www.imagemagick.org/

http://valokuva.org/?p=45 http://valokuva.org/?p=45

http://php.net/manual/en/book.imagick.php http://php.net/manual/zh/book.imagick.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM