dongqiang5865 2013-06-29 06:30
浏览 119
已采纳

TCPDF垂直拉伸文本

i am working on a project that need texts to be stretched with a given sized rectangle. I tried imagick for this but there some quality losses with it.

For example i have a box with sizes 203x78 (any size), and wrote a text "LOREM IPSUM LOREM" (any text). I want this text to be fully fit my given size 203x78, no matter font-size no matter any other things, just the quality and fully fit with my box.

I cound not find any method better than imagick with that way: firstly drawing transparent text with a closest font-size to my box (sure more little), and drawing image. After that, resizing it to my box size. When resizing it, i tried any of filter in imagick. There is no matter in this way except little sized texts. For eg. font size 20px and my certain box size is bigger than draw about 1-3px on any side. I mean, 20px drawn text size is 40x18, but my box is 41x20. so resizing it to 41x20 but blurred in any effect and effect value.

So i want to create my text with TCPDF and want to resize text to fit any given size. Fitting must be fully fit both horizontal and vertical, totally stretched. I chosed PDF because text in PDF in vectoral format and there is no losses while resizing any size.

TCPDF has a horizontal stretch but i could not find any way to stretch with both of sides.

Additional infos: using ttf files to create a text is required. transparent png output is required. horizontal stretch must not be with character spacing, all behaviors must be the same as vector resizing, JUST LIKE ADOBE ILLUSTRATOR.

illustrator resized texts, any size

Tries: i used php gd for this but very bad quality than imagick. i tried to install my server php-cairo but could not do it. i searched for inkscape to do this, but could not find a way working on command line. i tried imagick output > inkscape to convert vector, but totally fiasco. i tried TCPDF output > imagick to resize, but quality fiacso (imagick has no vector resizing capabilty)

Help!

  • 写回答

2条回答 默认 最新

  • dongzanghong4379 2013-07-03 03:56
    关注

    ImageMagick cannot be used to do that, because it is a "raster image processor". So in anyway, the image is gonna be rasterized before any operation (see Vector Image formats).

    I achieved to get something pretty clean with inkscape.

    First of all, we'll need a simple svg file containing the text. Such a file can easily generated with PHP or any other language:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <svg
       xmlns:dc="http://purl.org/dc/elements/1.1/"
       xmlns:cc="http://creativecommons.org/ns#"
       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:svg="http://www.w3.org/2000/svg"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
       version="1.1">
      <g>
        <text
           xml:space="preserve"
           style="font-size:40px;
                  font-style:normal;
                  font-weight:normal;
                  line-height:125%;
                  letter-spacing:0px;
                  word-spacing:0px;
                  fill:#000000;
                  fill-opacity:1;
                  stroke:none;
                  font-family:Helvetica"
           x="0"
           y="0"
           sodipodi:linespacing="125%"><tspan
             sodipodi:role="line"
             x="0"
             y="0">Hello World!</tspan></text>
      </g>
    </svg>
    

    From there, we can easily change the text, font, color... then the following command line do the trick (by adjusting the -w and -h parameters):

    inkscape filename.svg --export-png=filename.png -w800 -h300 --export-area-drawing
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部