douxigai8757 2018-12-10 14:31
浏览 56

在PHP中为imagestring添加多行/自动装配

I have a code which is working for me (see below),

But the textarea does not word-wrap, however I ask it nicely. I tried all I can find online, but not knowing PHP properly, it is a bit hard. I think I tried whatever there is for 'imagestring'. This piece of imagestring is stubborn, indeed. I thought I will trick it with css, nada. js, nada.

<?php
    if(isset($_POST['submit'])){
        $file_name = $_FILES['image']['name'];
        $file_size = $_FILES['image']['size'];
        $file_tmp = $_FILES['image']['tmp_name'];
        $file_type = $_FILES['image']['type'];
        move_uploaded_file($file_tmp,$file_name);  
        header ("Content-type: image/jpeg");

        $string = $_POST['caption'];
        $font = 12;
        $width = imagefontwidth($font) * strlen($string);
        $height = imagefontheight($font);
        $im = imagecreatefromjpeg($file_name);
        $x = imagesx($im) - $width;
        $y = imagesy($im) - $height;
        $backgroundColor = imagecolorallocate ($im, 255, 255, 255);
        $textColor = imagecolorallocate ($im, 0, 0,0);
        imagestring ($im, $font, $x, $y, $string, $textColor);
        $a = imagejpeg($im);
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Add Custom Text to Image</title>
    </head>
    <body>
            <form enctype="multipart/form-data" method="POST" action="">
            <input type="file" name="image"> 
                  <textarea name="caption" rows="10" cols="62" style="white-space: pre- 
                  line;" wrap="hard">
            <input type="submit" name="submit">
        </form>
    </body>
</html>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!