Imagttftext error

Hi everyone!

When generating a new text file thumbnail (*.md for example), I’m always getting this Error in the logs:

[PHP] Error: imagettftext(): Problem doing text layout at /var/www/nextcloud/lib/private/Preview/TXT.php#91

GET /index.php/core/preview?fileId=1986&x=32&y=32
from *** by *** at 2020-04-14T12:00:25+00:00

This is my server details:

## Server configuration detail

**Operating system:** Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64
**Webserver:** Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.29 (apache2handler)
**Database:** mysql 10.3.22
**PHP version:** 7.2.29

Modules loaded: Core, date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, apache2handler, bz2, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd, gettext, iconv, intl, json, exif, mysqlnd, PDO, Phar, posix, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlwriter, xsl, mysqli, pdo_mysql, pdo_sqlite, wddx, xmlreader, apcu, imagick, zip, Zend OPcache

**Nextcloud version:** 18.0.3 - 18.0.3.0
**Browser:** Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

And here is the TXT.php in question:

     36 class TXT extends ProviderV2 {
     37         /**
     38          * {@inheritDoc}
     39          */
     40         public function getMimeType(): string {
     41                 return '/text\/plain/';
     42         }
     43 
     44         /**
     45          * {@inheritDoc}
     46          */
     47         public function isAvailable(FileInfo $file): bool {
     48                 return $file->getSize() > 0;
     49         }
     50 
     51         /**
     52          * {@inheritDoc}
     53          */
     54         public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
     55                 $content = $file->fopen('r');
     56 
     57                 if ($content === false) {
     58                         return null;
     59                 }
     60 
     61                 $content = stream_get_contents($content,3000);
     62 
     63                 //don't create previews of empty text files
     64                 if(trim($content) === '') {
     65                         return null;
     66                 }
     67 
     68                 $lines = preg_split("/\r\n|\n|\r/", $content);
     69 
     70                 // Define text size of text file preview
     71                 $fontSize = $maxX ? (int) ((1 / 32) * $maxX) : 5; //5px
     72                 $lineSize = ceil($fontSize * 1.5);
     73 
     74                 $image = imagecreate($maxX, $maxY);
     75                 imagecolorallocate($image, 255, 255, 255);
     76                 $textColor = imagecolorallocate($image, 0, 0, 0);
     77 
     78                 $fontFile  = __DIR__;
     79                 $fontFile .= '/../../../core';
     80                 $fontFile .= '/fonts/NotoSans-Regular.ttf';
     81 
     82                 $canUseTTF = function_exists('imagettftext');
     83 
     84                 foreach($lines as $index => $line) {
     85                         $index = $index + 1;
     86 
     87                         $x = (int) 1;
     88                         $y = (int) ($index * $lineSize);
     89 
     90                         if ($canUseTTF === true) {
     91                                 imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
     92                         } else {
     93                                 $y -= $fontSize;
     94                                 imagestring($image, 1, $x, $y, $line, $textColor);
     95                         }
     96 
     97                         if(($index * $lineSize) >= $maxY) {
     98                                 break;
     99                         }
    100                 }
    101 
    102                 $imageObject = new \OC_Image();
    103                 $imageObject->setResource($image);
    104 
    105                 return $imageObject->valid() ? $imageObject : null;
    106         }
    107 }
# php -i | grep "FreeType"
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.8.0

Any help would be greatly appreciated.

P.S.: First post, let me know if need any more info.

Thanks!

Hi.
I had the same problem. And I decided to install php72-php-gd with dependencies. It happened to me most likely due to the fact that I changed the php version.
Try reinstalling gd for your php version or installing gd.

1 Like

Awesome, that did the trick! Thank you for your help @one_player! :+1:

I’m experiencing this problem since Nextcloud 18.0.4 and I have version 7.4.5 of both php and php-gd installed, so having the same version installed didn’t solve it for me, @one_player

Same here under NC 18.0.4.2 and PHP 7.4.5 (ubuntu 18.04.4)

Difference - i could install php-gd but php7.4-gd was already the latest version …

from my command shell …

[user@cloudserver ~]# sudo apt-get install -y php7.4-dev Paketlisten werden gelesen… Abhängigkeitsbaum wird aufgebaut… Statusinformationen werden eingelesen… php7.4-dev ist schon die neueste Version (7.4.5-1+ubuntu18.04.1+deb.sury.org+1). php7.4-dev wurde als manuell installiert festgelegt. 0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

[user@cloudserver ~]# sudo apt-get install -y php7.4-gd Paketlisten werden gelesen… Abhängigkeitsbaum wird aufgebaut… Statusinformationen werden eingelesen… php7.4-gd ist schon die neueste Version (7.4.5-1+ubuntu18.04.1+deb.sury.org+1). 0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

[user@cloudserver ~]# sudo apt-get install -y php-gd Paketlisten werden gelesen… Abhängigkeitsbaum wird aufgebaut… Statusinformationen werden eingelesen… php-gd ist schon die neueste Version (2:7.4+75+ubuntu18.04.1+deb.sury.org+1). 0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

[user@cloudserver ~]# sudo apt-get install -y php-dev Paketlisten werden gelesen… Abhängigkeitsbaum wird aufgebaut… Statusinformationen werden eingelesen… php-dev ist schon die neueste Version (2:7.4+75+ubuntu18.04.1+deb.sury.org+1). 0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

my nextcloud logfile contains several entries of this kind:

imagettftext(): Problem doing text layout at /var/www/nextcloud/lib/private/Preview/TXT.php#91

I’m pretty sure that those logs appear since changing the PHP version to 7.4.x

Same with php7.3 and php7.3-gd, ubuntu 18.04 and nextcloud 18.0.4

I have only had this error in my logs, which also makes cron fail since I upgraded my dedicated server to Nextcloud: 18.0.4

Hello,

I have the exact same error in my nextcloud log:

imagettftext(): Problem doing text layout at /usr/share/webapps/nextcloud/lib/private/Preview/TXT.php#91

This error first appeared in my nextcloud log on 6/1/20 (June 1st) and appears numerous times.

I tried the “fix,” but reinstalling gd and php-gd do not work for me.

The Collabora app was just updated, and I use Collabora quite a lot.

Could this new version of the Collabora app be the cause?

Do you all use the Collabora app in nextcloud as well?

PS: I have the current version of nextcloud, PHP, gd, php-gd installed (Arch linux)

buzz

`imagettftext(): Problem doing text layout at /usr/local/www/nextcloud/lib/private/Preview/TXT.php#92`

I have this also and I do not use Collabora. I have practically a new installation without upgrading anything.
Installed in a FreeNAS-11.3-U3.2 jail are:
Nextcloud 19.0.0
PHP 7.4.6
MariaDB 10.2.32

Would be nice to find out how to solve it.

I had a redis password issue (related to Redis 6 update). When I resolved it, I checked the log file, and I had about seven new error entries about imagettftext() in my log.

However, after I rebooted the server, there has not been another occurrence of the imagettftext() errors.

buzz

I updated everything since my last post and I still have this error. As far as I know I don’t have any redis issues.
There must be something else there.

1 Like

These errors are now back for me as well:

imagettftext(): Problem doing text layout at /usr/share/webapps/nextcloud/lib/private/Preview/TXT.php#92

This is repeated many times in my Nextcloud log file. In fact, it’s the only error message in my Nextcloud log file.

Hello everyone,

I started getting this error then I made a fix for the PHP session_Start() which had me edit a couple of lines in the Internal.php.

After I made the change I no longer got the error stated above, but when editing documents like a .md I now get imagettftext(): Problem doing text layout at /usr/local/www/nextcloud/lib/private/Preview/TXT.php#92

I have Nextcloud 19.0.1
PHP74-7.4.7
php74-gd-7.4.7

I don’t have php72-php-gd installed well I don’t think unless that is PHP74-7.4.7
php74-gd-7.4.7

Does anyone know if there is a fix for this?

Thank you for reading,
Joe

Months later, and I’m still receiving this error. I have the following versions:

php 7.4.12-2 [installed]
php-apcu 5.1.19-1 [installed]
php-apcu-bc 1.0.5-3 [installed]
php-fpm 7.4.12-2 [installed]
php-gd 7.4.12-2 [installed]
php-imap 7.4.12-2 [installed]
php-intl 7.4.12-2 [installed]
php-pspell 7.4.12-2 [installed]
php-snmp 7.4.12-2 [installed]
php-sqlite 7.4.12-2 [installed]
php-tidy 7.4.12-2 [installed]
php-xsl 7.4.12-2 [installed]
php-geoip 1.1.1-5 [installed]
php-igbinary 3.1.6-1 [installed]
php-imagick 3.4.4-8 [installed]
php-redis 5.3.2-1 [installed]
php-pear 1:1.10.19-2 [installed]
php-smbclient 1.0.0-2 [installed]
php-pam 2.1.1-2 [installed]

Nextcloud 20.0.1-1