function create_rys() { $im = imagecreatetruecolor (200, 200); $col_red = ImageColorAllocate($im,255,0,0); Imagettftext($im,12,45,50,50,$col_red,"arial","Abcde"); if(!$im) { $im = imagecreatetruecolor (150, 30); $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc); } return $im; } $img = create_rys(); imagepng($img); imagedestroy($img);
Rysunek bezpośrednio http://localhost/rys.php wyświetla mi się w przeglądarce. Tak samo z innej strony storna.php
<img src="rys.php" />
Jednak przy próbie pobraniu koloru w skrypcie na strona.php otrzymuję błąd: "Warning: imagecreatefrompng(): 'rys.php' is not a valid PNG file".
A zmienna $file_info zwraca "text/x-php" zamiast PNG, ale nie wiem dlaczego.
$file1 = 'rys.php'; $file_info = new finfo(FILEINFO_MIME); //$im = ImageCreateFromPng( 'http://localhost/rys.php' ); //$im = ImageCreateFromPng( 'http://nazwa_domeny.pl/rys.php' ); $im = ImageCreateFromPng( 'rys.php' ); $rgb = imagecolorat($im, 1, 1); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF;
Dziękuję za wszelkie sugestie.