Fixed support for UTF-8 image text if using broken GD
authorAlexander Ebert <ebert@woltlab.com>
Sat, 13 Oct 2012 23:25:35 +0000 (01:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 13 Oct 2012 23:25:35 +0000 (01:25 +0200)
Fixes #576

wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php

index 4d6283f19a4f7bd46d9e7074944626dc79427bd7..d4ff07fa330807f681e7ae72639a3dbb0cd37f73 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\image\adapter;
+use wcf\util\StringUtil;
+
 use wcf\system\exception\SystemException;
 
 /**
@@ -176,6 +178,13 @@ class GDImageAdapter implements IImageAdapter {
         * @see wcf\system\image\adapter\IImageAdapter::drawText()
         */
        public function drawText($string, $x, $y) {
+               if (!StringUtil::isUTF8($string)) {
+                       throw new SystemException("Only UTF-8 encoded text can be written onto images"); // GD is buggy with UTF-8
+               }
+               
+               // convert UTF-8 characters > 127 to their numeric representation, e.g. A -> &#65;
+               $string = mb_encode_numericentity($string, array(0x0, 0xFFFF, 0, 0xFFF), 'UTF-8');
+               
                imageString($this->image, 3, $x, $y, $string, $this->color);
        }