dongzeao5047 2014-01-25 21:12
浏览 24
已采纳

为mysql行的每一行创建一个图像

Right now I have this (I'm going to add more once it works, but I wanted to keep it simple for testing)

    <?php
    try {
    $dbh = new PDO('mysql:host= info goes here');
    foreach($dbh->query('SELECT * from table_name') as $row) {
 header('Content-type: image/jpeg');
  $jpg_image = imagecreatefromjpeg('cert.jpg');
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  $font_path = 'arial.TTF';
  $text = $row['fname'];
  $font_size = 25;
  imagettftext($jpg_image, $font_size, 0, 500, 100, $white, $font_path, $text);
  imagejpeg($jpg_image);
  imagedestroy($jpg_image);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>

The code works, but it is only taking the first name, I'm wondering if there is a way to make it so that it will make one for each name (line) until it reaches the end of the row. I'm planning on saving one image per name. I'm trying to make something that fills in information on a certificate and saves each one in a folder on the server

  • 写回答

1条回答 默认 最新

  • douyi1084 2014-01-25 21:28
    关注

    Just make an unique filename for it everytime, e.g. based on some field in the database, a timestamp or a random number and pass it to imagejpeg. See the manual about the function

    imagejpeg($jpg_image, "some/dir/some_unique_filename.jpeg");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c