doudou6719 2014-10-24 16:17
浏览 31
已采纳

如何用动态文本php创建图像

I need to create images dynamically, i.e the text on the image will be dynamic. Is there any way to generate the images with dynamic text and save it? I have tried the following

<?php

header("Content-type: image/jpeg");
$imgPath = 'image.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = "THIS TEXT IS DYNAMIC";
$fontSize = 3;
$x = 115;
$y = 185;
imagestring($image, $fontSize, $x, $y, $string, $color);
imagejpeg($image);
?> 

but it shows me the image with the text, but it does not save the image with this text written on it. I need to save the image with the text written on it

  • 写回答

1条回答 默认 最新

  • dousidan1279 2014-10-24 16:22
    关注

    Using the function signature

    bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )
    

    you need to set a path to a file using the second parameter.

    Do it like this:

    $saveToPath = dirname( __FILE__ ) . '/imageCache/myImageFile.jpg';
    imagejpeg( $image, $saveToPath );
    
    header( 'Content-Type: image/jpeg' );
    readfile( $saveToPath );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线