使用 PHP 显示多个图像 [英] Display multiple images with PHP

查看:76
本文介绍了使用 PHP 显示多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个从数据库返回图片的 PHP 脚本.我现在使用循环一次返回 5 张图片,但我认为它们都是重叠的,所以我只看到了一张.如何将每张图片移动几个像素,以便我可以看到其他图片?

I have this PHP script that returns pictures from the database. I am using a loop now to return 5 pictures at once, but I think they are all overlapping so I am only seeing one. How can I shift each picture a couple of pixels over so I can see the other pictures?

<?php
    $mysqli=mysqli_connect('localhost','root','','draftdb');
    if (!$mysqli)
    die("Can't connect to MySQL: ".mysqli_connect_error());

    $param = isset($_GET['rarity']) ? $_GET['loopcount'] :null;

    $stmt = $mysqli->prepare("SELECT display.PICTURE_ID 
    FROM cards  
    INNER JOIN display ON cards.DISPLAY_ID = display.DISPLAY_ID 
    WHERE display.DISPLAY_ID=? AND cards.CARD_TYPE =?" );

    $cardtype='Rare';


    for ($i=0; $i<=5; $i++) 
    {
      $num[$i] = rand(16,30);
       for ($j=0; $j<$i; $j++) 
       {            
          while ($num[$j] == $num[$i])
          {              
             $num[$i] = rand(16,30);   
          }          

                   $displayid= array_shift($num);   

       }   



    $stmt->bind_param("si", $displayid, $cardtype);
    $stmt->execute();
    $stmt->bind_result($image);
    $stmt->fetch();
    header("Content-Type: image/jpeg");
    echo $image; 
    }


    ?>

推荐答案

您无法使用 php显示"图像.您可以使用 <img> 标记对 HTML 执行此操作.你所做的是打印原始图像数据,然后告诉浏览器这是一张图片.我不确定如果你这样做并打印多张图像会发生什么,但这取决于浏览器它应该如何处理.

You can't "display" an image with php. You do that with HTML using the <img> tag. What you do is printing the raw image data and then telling the browser It's a picture. I'm not sure what's gonna happen if you do this and print multiple images, but It's up to the browser how It should handle this probably.

这有时是使用 one 图像完成的,例如,如果您将它们作为 blob 存储在数据库中.但不是为了显示它们.

This is sometimes done with one image if you for example store them as blobs in a database. But not for this purpose of displaying them.

如果您想合并图像,您可以使用 PHP 中的 GD 库来完成.

If you want to merge images you can do this with the GD library in PHP.

这篇关于使用 PHP 显示多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆