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

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 11: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条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序