duanjiao5723 2016-10-08 03:40
浏览 67
已采纳

php gd垂直文本图像

I would like to put on a picture in vertical text in PHP:

function scrivi($scrivi, $p) {
    $imgResource = imagecreatefromjpeg($p);
    $textcolor = imagecolorallocate($imgResource, 255, 255, 255);
    $fontPath = "st.ttf";
    $fontSize = "18";
    $rotation = "270"; // counter-clockwise rotation
    $text = "this is a text";
    $textCoords = imagettfbbox($fontSize, $rotation, $fontPath, $text);
    $x = 36;
    $y = 36;
    imagettftext($imgResource, $fontSize, $rotation, $x, $y, $textcolor, $fontPath, $text);
    unlink($p);
    imagejpeg($imgResource, $p, 100);
    imagedestroy($imgResource);
}

It works well only that I would like that the letters are turned this is an example using the function

enter image description here

Instead I would like to

enter image description here

an idea could be to wrap each letter

  • 写回答

1条回答 默认 最新

  • doukun5339 2016-10-08 05:21
    关注

    All you really need to do is split the text into an array, loop it, then offset the y by the height + leading of the font character:

    function scrivi($p,$text)
        {
            $imgResource    =   imagecreatefromjpeg($p);
            $textcolor      =   imagecolorallocate($imgResource, 255,255, 255);
            $fontPath       =   __DIR__."/st.ttf";
            $fontSize       =   "18";
            $x  =   36 ;
            $y  =   36;
            foreach(str_split($text) as $char) {
                $textCoords =   imagettfbbox($fontSize, 0, $fontPath, $char);
                imagettftext($imgResource, $fontSize, 0, $x, $y, $textcolor,$fontPath,$char);
                $y  +=  24;
            }
            unlink($p);
            imagejpeg($imgResource,$p,100);
            imagedestroy($imgResource);
        }
    
    scrivi('http://imgtops.sourceforge.net/bakeoff/bw.jpg',"Cats are great");
    

    Gives you:

    enter image description here

    (Image credit: http://imgtops.sourceforge.net/bakeoff/)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献