【问题标题】:How to create images with dynamic text php如何使用动态文本 php 创建图像
【发布时间】:2014-10-24 16:17:41
【问题描述】:

我需要动态创建图像,即图像上的文本将是动态的。有没有办法用动态文本生成图像并保存? 我已经尝试了以下

<?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);
?> 

但它向我显示了带有文本的图像,但它不会保存带有此文本的图像。我需要保存带有文字的图像

【问题讨论】:

    标签: php image text


    【解决方案1】:

    使用函数签名

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

    您需要使用第二个参数设置文件的路径。

    这样做:

    $saveToPath = dirname( __FILE__ ) . '/imageCache/myImageFile.jpg';
    imagejpeg( $image, $saveToPath );
    
    header( 'Content-Type: image/jpeg' );
    readfile( $saveToPath );
    

    【讨论】:

    • 它告诉我cannot display because it contains errors
    • 还是一样,能否请您更改我的代码。我不知道我必须在哪一行添加这段代码
    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2012-07-30
    • 1970-01-01
    相关资源
    最近更新 更多