imagettftext

Underline text using imagettftext

喜夏-厌秋 提交于 2019-12-07 12:44:50
问题 My question is, how do I underline all the text in the image? Code: function createImage($text) { $text .= "\n"; $text = wordwrap($text, 40, "\n"); $newlines = substr_count($text, "\n"); if($newlines == 0) { $height = 30; } else { $height = 30*$newlines-$newlines*7; } putenv('GDFONTPATH=' . realpath('.')); header('Content-Type: image/png'); $im = imagecreatetruecolor(315, $height); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black =

imagettftext cannot open font file

若如初见. 提交于 2019-12-07 01:35:22
问题 Using the example from php.net I get a warning, and the image is not rendered correctly. I supply a full path to the .ttf file like so: /var/www/public/myfont.ttf PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in <phpfile> I am using a custom .ttf font found here. I can open the file fine in Ubuntu as a valid font file. I also attempted other fonts, with the same result. I am using Ubuntu 10.04 LTS 32 bit, with apache2, php5,

Generate Captcha Image PHP

我们两清 提交于 2019-12-06 11:52:27
问题 I want to generate Captcha Image using PHP imagettftext. And following is my code. It gives an empty image. I want to resolve this issue. I have tested the code but was unable to find why the image is not bieng showed although my random text is being passed to the function of captcha image generation. <?php function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $length; $i++) {

Underline text using imagettftext

妖精的绣舞 提交于 2019-12-06 01:21:19
My question is, how do I underline all the text in the image? Code: function createImage($text) { $text .= "\n"; $text = wordwrap($text, 40, "\n"); $newlines = substr_count($text, "\n"); if($newlines == 0) { $height = 30; } else { $height = 30*$newlines-$newlines*7; } putenv('GDFONTPATH=' . realpath('.')); header('Content-Type: image/png'); $im = imagecreatetruecolor(315, $height); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); $purple = imagecolorallocate($im, 97, 26, 139); imagefilledrectangle($im, 0

imagettftext cannot open font file

为君一笑 提交于 2019-12-05 05:27:04
Using the example from php.net I get a warning, and the image is not rendered correctly. I supply a full path to the .ttf file like so: /var/www/public/myfont.ttf PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in <phpfile> I am using a custom .ttf font found here . I can open the file fine in Ubuntu as a valid font file. I also attempted other fonts, with the same result. I am using Ubuntu 10.04 LTS 32 bit, with apache2, php5, freetype6 and php5-gd installed. I also attempted to chmod 777 file and folder with ttf file, with the

PHP - imagettftext not working and GD installed

…衆ロ難τιáo~ 提交于 2019-12-05 04:50:30
It's being long hours that I'm still looking for answer to this problem.. All the solutions I find are around catching the font name but I am pretty sure this isn't my problem. It looks like GD is installed array(11) { ["GD Version"]=> string(27) "bundled (**2.0.34 compatible**)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"

Using the imagettftext function with multiple lines? Anyone done this before?

為{幸葍}努か 提交于 2019-12-04 12:09:53
问题 I'm creating transparent text -> png images with php and so far so good. The only problem is that I want the ability to have the text word wrap due to a fixed width.. Or alternatively be able to insert breaklines into the text. Has anyone had any exp doing this? here is my code... <?php $font = 'arial.ttf'; $text = 'Cool Stuff! this is nice LALALALALA LALA HEEH EHEHE'; $fontSize = 20; $bounds = imagettfbbox($fontSize, 0, $font, $text); $width = abs($bounds[4]-$bounds[6]); $height = abs(

PHP imagettftext baseline workaround

故事扮演 提交于 2019-12-03 06:25:50
I am writing to print text to an image using PHP. However, the function imagettftext() uses the baseline, whereas I need the text vertically centered. So, I either need a method to print text with y not the distance from top to baseline, but from top to top of bounding box OR I need a method using which I could determine the distance between top of bounding box and baseline. Apparently, I am confusing you. So, to make it clear: I am aware of the function imagettfbbox() . Using that function I can determine height and width of resulting text box. Its height, however, is utterly useless for

绝对详解PHP 的imageTtfText()函数

匿名 (未验证) 提交于 2019-12-02 22:11:45
图片处理,是许多程序的功能之一;而文字渲染则是绘图的基本组成部分。PHP通过很多扩展库来支持图片的处理,最常用的还是GD库,通过一系列imagexxx()函数来提供绘图功能。本文专注于非常细小的一点:绘制文字。熟悉Win32的人都知道,TextOut()就可以轻松显示任何文字了,然而到了PHP的世界里,有些事情并不轻松。 1 详细解释imageTtfText()函数 对于PHP绘图初学者,首先遇到的一个问题就是,imageString()这个函数并不支持汉字的绘制。这往往会给入门者当头一棒,不过不要着急,因为还有一个imageTtfText()函数,这个函数能绘制UTF-8编码的字符串,当然可以绘制汉字了。然而使用它并不十分简单。先来看看其原型声明: 一共有8个参数,缺一不可,而且官方文档这些参数的解释并不透彻,这里笔者尽力做更详细清晰的解释: 这个是画布资源,无需再解释; (2)$size ,官方文档的解释是,字体大小,其长度单位依赖于GD库的版本,对于GD1来说是像素,对于GD2来说是磅(point)。现在一般都是GD2了,那么这个磅究竟是什么意思呢?这涉及到字体设计的基本知识。 简单来说,磅是一个长度度量单位,如果把一英寸等分成72份,每一份就是1磅。这里需要强调的是,磅是个绝对物理单位,与显示设备无关。 而像素呢?像素没有固定的大小,而是与分辨率相关

Accented characters not showing when using imagettftext with otf but showing with ttf

心不动则不痛 提交于 2019-12-02 05:11:29
I'm using imagettftext to generate images from OpenType files. Everything works until I try to use an accented character (e.g. å) or a character such as √. In their place I get the .notdef glyph. The fonts I'm using definitely have these characters. To make things even more frustrating, when I use a TTF everything works as expected. Any ideas? Thanks Sorry to tell you, but PHP OTF supports only standard Ascii characters. It's a well known fact that special characters in OTF only very rarely work. I'm afraid you will have to stick with TTF until they correct that. Not true! (answer 1)