如何在图像下面添加说明?

时间:2013-02-06 01:19:35

标签: php mysql image

我创建了一个包含blob图像和描述的数据库。该描述连接到具有相同ID的blob数据。在此代码中,描述显示在其图像旁边。

显示图片页面

$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
echo '<'.'img src="id.php?id='.$data['id'].'">';
$short_description = substr($data['description'], 0, 10);
$long_description = $data['description'];
echo $long_description;


}

echo "<br><a href='Photosite.php'>Upload a Photo</a>";

将blob转换为显示页面的jpegs

$id = abs($_GET['id']);
$query = mysql_query("SELECT * FROM `photo`.`photo` WHERE id='$id'");
$data = mysql_fetch_array($query) or die (mysql_error());
$image = $data['image'];
$description = $data['description'];


$jpgimage = imagecreatefromstring($image);




    $image_width = imagesx($jpgimage);
    $image_height = imagesy($jpgimage);

    $new_size = ($image_width + $image_height)/($image_width*($image_height/45));
    $new_width = $image_width * $new_size;
    $new_height = $image_height * $new_size;

    $new_image = imagecreatetruecolor($new_width, $new_height);


    imagecopyresized($new_image, $jpgimage, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
      $imagearray = imagejpeg($new_image, null);
      header('Content-type: image/jpeg');

       echo $imagearray;

我的问题是如何让描述显示在显示的图像下?并且在描述旁边的图像旁边的描述旁边没有图像等等?

大帮助谢谢!是的,我知道我的一些功能已经过时,无需提醒我,谢谢!

2 个答案:

答案 0 :(得分:1)

如果您希望彼此相邻的图像以及每张图像下方的描述,则:

<?php
$max_width = '200px'; // Set this to whatever the image's width is.

$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
    // short_description doesn't look like it's being used... ??
    $short_description = substr($data['description'], 0, 10);
    $long_description = $data['description'];
    echo '<div style="float:left;width:'.$max_width.';">';
    echo '    <img src="id.php?id='.$data['id'].'" />';
    echo '    <br style="clear:both;" />';
    echo      $long_description;
    echo '</div>';
}
echo "<br style="clear:both;"><a href='Photosite.php'>Upload a Photo</a>";    

否则,如果您希望图像位于彼此之下且图像下方有描述,则:

<?php
$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
    // short_description doesn't look like it's being used... ??
    $short_description = substr($data['description'], 0, 10);
    $long_description = $data['description'];
    echo '<div>';
    echo '    <img src="id.php?id='.$data['id'].'">';
    echo '    <br style="clear:both;" />';
    echo      $long_description;
    echo '</div>';
}
echo "<br style="clear:both;"><a href='Photosite.php'>Upload a Photo</a>";    

答案 1 :(得分:0)

在说明之前尝试换行。您还可以考虑一个简单的两行一列表。