Reputation: 288
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.
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!
Upvotes: 2
Views: 2753
Reputation: 63
A way I ve found is by making transformations and outputting html
$pdf->StartTransform();
$pdf->Scale(100,150);
// Output html.
$html=('sample text');
$pdf->writeHTMLCell($w=50, $h=10, $x='', $y='', $html, $border=1, $ln=1, $fill=0, $reseth=true, $align='C', $autopadding=true);
$pdf->StopTransform();
Upvotes: 0
Reputation: 1675
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
Upvotes: 3