]> source.dussan.org Git - nextcloud-server.git/commitdiff
implement a txt preview fallback for the case that ttf is not support
authorGeorg Ehrke <developer@georgehrke.com>
Mon, 28 Jul 2014 09:56:43 +0000 (11:56 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Thu, 7 Aug 2014 20:59:25 +0000 (22:59 +0200)
lib/private/preview/txt.php

index 063543c6279ae62a0f53c5d84d943393408b198f..3059757fcecb734b9519e508aae4ede59b910fc5 100644 (file)
@@ -44,13 +44,20 @@ class TXT extends Provider {
                $fontFile .= '/../../../core';
                $fontFile .= '/fonts/OpenSans-Regular.ttf';
 
+               $canUseTTF = function_exists('imagettftext');
+
                foreach($lines as $index => $line) {
                        $index = $index + 1;
 
                        $x = (int) 1;
                        $y = (int) ($index * $lineSize);
 
-                       imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
+                       if ($canUseTTF === true) {
+                               imagettftext($image, $fontSize, 0, $x, $y, $textColor, $fontFile, $line);
+                       } else {
+                               $y -= $fontSize;
+                               imagestring($image, 1, $x, $y, $line, $textColor);
+                       }
 
                        if(($index * $lineSize) >= $maxY) {
                                break;