Народ! Подскажите куда смотреть, необходимо средствами php создать картинку на которой будет таблица на основе данных из БД с последующей отправкой её в telegram при помощи бота.
@lVlist наверное для бота абсолютно неважно как создавалась картинка и наоборот, при создании неважно что с ней будет. Не надо лишних сущностей, короче ))) Думай как программист. Тебе надо графики на PHP? Есть такие библиотеки и они гуглятся на ура. Но в мире JS эта тема развита гораздо лучше. Или какого рода картинка тебе нужна?
Генерация изображения из таблицы найдено в интернете. Код нужно править под свой проект. PHP: <?php session_start(); $data = array ( array ( 'name' => 'John', 'score' => 31004, 'age' => 31, 'email' => 'john.doe@gmail.com' ), array ( 'name' => 'Mary', 'score' => 21789, 'age' => 21, 'email' => 'maryx@amazon.com' ), array ( 'name' => 'Rumpelstiltskin', 'score' => 2345, 'age' => 101, 'email' => 'rumpel@gmail.com' ), array ( 'name' => 'Sarah', 'score' => 345, 'age' => 25, 'email' => 'sarah123@aol.com' ) ); $_SESSION['imagedata'] = $data; echo "<IMG src='mytableimage.php'>"; mytableimage.php PHP: <?php session_start(); $data = $_SESSION['imagedata']; /** * get max widths for each column */ $cols = array() ; $colvals = array(); $count = 0; foreach ($data as $row ) { foreach ($row as $field => $val) { if (!isset($cols[$field])) { $cols[$field] = strlen($val); } else { $cols[$field] = max($cols[$field], strlen($val)); } $colvals[$count][] = $val; } $count++; } /** * calculate text widths in pixels */ $pad = 4; $colnames = array_keys($cols); $colwidths = array_values($cols); foreach ($colwidths as $k=>$v) { $colwidths[$k] = $v * imagefontwidth(3) + 2 * $pad; } /** * calc image size and create */ $rowheight = imagefontheight(3) + 2 * $pad; $numrows = count ($data) + 1; $ih = $numrows * $rowheight; $iw = array_sum ($colwidths); $im = imagecreate($iw, $ih); $bg = imagecolorallocate($im, 0xAA, 0xD0, 0xD0); $bdr = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $tcol = imagecolorallocate($im, 0,0,0); /** * draw cell borders */ $x = $y = 0; for ($y=0; $y < $ih; $y += $rowheight) imageline($im, 0, $y, $iw, $y, $bdr); for ($i=0, $n=count($colnames); $i <= $n; $i++) { imageline($im, $x, 0, $x, $ih, $bdr); $x += $colwidths[$i]; } /** * headings */ foreach ($colnames as $col=>$text) { $x = textCenter($col, $text, $pad, 3, $colwidths); $y = $pad; imagestring($im, 3, $x, $y, $text, $tcol); } /** * data */ foreach ($colvals as $row=>$items) { foreach ($items as $col=>$text) { $y = ($row+1) * $rowheight + $pad; $x = is_numeric($text) ? textRight($col,$text,$pad,3,$colwidths) : textLeft($col,$text,$pad,3,$colwidths); imagestring($im, 3, $x, $y, $text, $tcol); } } header ("content-type: image/png"); imagepng($im); imagedestroy($im); /****************************************** * text positioning functions *******************************************/ function textLeft ($col, $text, $pad, $font, &$colwidths) { $x = array_sum(array_slice($colwidths, 0, $col)) + $pad; return $x; } function textRight ($col, $text, $pad, $font, &$colwidths) { $tw = strlen($text) * imagefontwidth($font); $x = array_sum(array_slice($colwidths, 0, $col+1)) - $pad - $tw; return $x; } function textCenter ($col, $text, $pad, $font, &$colwidths) { $tw = strlen($text) * imagefontwidth($font); $x1 = array_sum(array_slice($colwidths, 0, $col)) ; $x2 = array_sum(array_slice($colwidths, 0, $col+1)) ; return ($x1 + $x2 - $tw)/2; }