[[oktatas:programozás:php|< PHP]] ====== PHP Grafikonok ====== ===== Fontok a grafikonra rajzoláshoz ===== * DejaVuval * Linux Libertine * Liberation ===== Saját grafikon ===== "; echo << EOT; function genGrafikon($adat) { $meret = count($adat); $width = 400; if($meret > 10) { $n = $meret - 10; $width = $width + (40 * $n); } $img = imagecreatetruecolor($width, 400); $feher = imagecolorallocate($img, 255, 255, 255); $kek = imagecolorallocate($img, 0, 0, 255); imagefill($img, 1, 1, $feher); //Szöveg kiírása $szoveg = "Tégla"; $szoveg = iconv("UTF-8", "ISO-8859-2", $szoveg); imagestring($img, 5, 100, 0, $szoveg, $kek); $kepMagassag = 400; $max = 100; $x1 = 10; $x2 = $x1 + 20; for($i = 0; $i<$meret; $i++) { $y1 = $kepMagassag - ($adat[$i] * ($kepMagassag / $max)); //Téglalap elkészítése imagerectangle($img, $x1, $y1, $x2, 400, $kek); imagefill($img, $x1 + 1, 399, $kek); $x1 = $x1 + 40; $x2 = $x2 + 40; } return $img; } ?> ===== JpGraph ===== ==== Hiba megkerülése ==== Ha nincs engedélyezve a telepített PHP rendszeredben a imageantialias() függvényt a következő hibaüzenetet kapjuk. {{:oktatas:programozás:php:jpgraph-error.png|}} Keressük meg a JpGraphError::RaiseL(25128); kezdetű sort a **gd_image.inc.php** fájlban majd tegyük megjegyzésbe: function SetAntiAliasing($aFlg=true) { $this->use_anti_aliasing = $aFlg; if( function_exists('imageantialias') ) { imageantialias($this->img,$aFlg); } else { //JpGraphError::RaiseL(25128);//('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.') } } ==== Hiba javítása ==== Ez a megoldás PHP5 újrafordításával valósul meg, ezért hosszú ideig tarthat. Telepíteni viszont csak a php5-gd csomagot telepítjük újra. A leírás Debian Squeeze rendszeren készült. Ellenőrizzük az imageantialias() függvény meglétét: php -r "var_dump(function_exists('imageantialias'));" Az eredmény ez lehet: bool(false) Láthatjuk, hogy nincs engedélyezve. Szükséges eszközök telepítése: apt-get install build-essential debhelper fakeroot apt-get remove php5-gd cd /usr/src/ apt-get source php5 apt-get build-dep php5 cd php5-5.3.3/ Szerkesszük a "debian/rules" fájlt és cseréljük le a következő sort: --with-gd=shared,/usr --enable-gd-native-ttf erre: --with-gd=shared --enable-gd-native-ttf Elkészítjük az új csomagot: dpkg-buildpackage -rfakeroot -uc -b A következő hibát kapjuk: # start our own mysql server for the tests /bin/sh debian/setup-mysql.sh 1025 /usr/src/php5-5.3.3/mysql_db Timed out waiting for mysql server to be available kill: 65: No such process kill: 65: No such process make: *** [test-result.txt] Error 1 dpkg-buildpackage: error: debian/rules build gave error exit status 2 Javítjuk a debian/setup-mysql.sh fájlban: # Start the daemon $mysqld > $datadir/run.log 2>&1 & helyett: $mysqld --user=root > $datadir/run.log 2>&1 & Removing patch fix-segfault-in-pgsql_stmt_execute-when-postgres-is-down.patch Restoring ext/pdo_pgsql/pgsql_statement.c Patch fix-memory-leak-inside-highlight_string.patch does not remove cleanly (ref resh it or enforce width -f) make: *** [unpatch] Error 1 dpkg-buildpackage: error: fakeroot debian/rules clean gave error exit status 2 Megoldásként futtasuk a következő parancsot a PHP5-5.3.3 könyvtárban: QUILT_PATCHES=debian/patches quilt refresh Telepítjük az új csomagot: cd .. dpkg -i php5-gd_5.3.3-7+squeeze14_i386.deb [[http://www.dnasir.com/2011/04/23/tutorial-how-to-enable-php5s-imageantialias-on-ubuntu-10-10/|Ugyanez Ubuntu rendszeren]]