function mathimage($text, $size) { $nameimg = md5(trim($text) . $size) . '.png'; $v = detectimg($nameimg); if ($v == 0) { global $symboles, $fontesmath; import('content/math/mathpublisher'); $formula = new expression_math(tableau_expression(trim($text))); $formula->dessine($size); $v = 1000 - imagesy($formula->image) + $formula->base_verticale + 3; imagepng($formula->image, DIR_IMG . '/math_' . $v . '_' . $nameimg); } $valign = $v - 1000; $text = htmlentities(strip_tags($text), ENT_COMPAT, 'ISO-8859-1'); return '<img src="/images/maths/math_' . $v . '_' . $nameimg . '" style="vertical-align:' . $valign . 'px;display:inline-block;background-color:#FFFFFF;" alt="' . $text . '" title="' . $text . '"/>'; }
/** * Render formule image * @return */ public function render() { $expression = new expression_math(tableau_expression(trim($this->_formula))); $expression->dessine($this->_symbol_size); $width = imagesx($expression->image) + $this->_symbol_padding; $height = imagesy($expression->image) + $this->_symbol_padding; $image = imagecreatetruecolor($width, $height); imagefill($image, 0, 0, 0xffffff); imagecopy($image, $expression->image, 10, 10, 0, 0, $width - 20, $height - 20); ob_start(); // buffers future output imagepng($image); // writes to output/buffer $b64 = base64_encode(ob_get_contents()); // returns output ob_end_clean(); // clears buffered output return "data:image/png;base64," . $b64; }
function mathimage($text, $size, $pathtoimg) { /* Creates the formula image (if the image is not in the cache) and returns the <img src=...></img> html code. */ global $dirimg; $nameimg = md5(trim($text) . $size) . '.png'; $v = detectimg($nameimg); if ($v == 0) { //the image doesn't exist in the cache directory. we create it. $formula = new expression_math(tableau_expression(trim($text))); $formula->dessine($size); $v = 1000 - imagesy($formula->image) + $formula->base_verticale + 3; //1000+baseline ($v) is recorded in the name of the image ImagePNG($formula->image, $dirimg . "/math_" . $v . "_" . $nameimg); } $valign = $v - 1000; return '<img src="' . $pathtoimg . "math_" . $v . "_" . $nameimg . '" style="vertical-align:' . $valign . 'px;' . ' display: inline-block ;" alt="' . $text . '" title="' . $text . '"/>'; }
/** * @inheritdoc */ protected function renderImage($code) { require __DIR__ . '/mathpublisher.php'; $formula = new \expression_math(tableau_expression(trim($this->getExpresion($code)))); $formula->dessine($this->size); ob_start(); switch ($this->imageFormat) { case self::JPEG_FORMAT: imagejpeg($formula->image); break; case self::PNG_FORMAT: imagepng($formula->image); break; } imagedestroy($formula->image); return ob_get_clean(); }
function mathimage($text, $size, $pathtoimg, $color = '#000000', $bg_color = '#ffffff') { /* Creates the formula image (if the image is not in the cache) and returns the <img src=...></img> html code. */ global $dirimg, $dirfonts, $mp_debug, $mpfont_red, $mpfont_green, $mpfont_blue, $mpbg_red, $mpbg_green, $mpbg_blue; global $_VERSION; list($mpfont_red, $mpfont_green, $mpfont_blue) = html2rgb($color); list($mpbg_red, $mpbg_green, $mpbg_blue) = html2rgb($bg_color); $text = stripslashes($text); $size = max($size, 10); $size = min($size, 24); $nameimg = md5(trim($text) . $size . $color . $bg_color) . '.png'; $v = detectimg($nameimg); if ($v == 0) { //the image doesn't exist in the cache directory. we create it. $formula = new expression_math(tableau_expression(trim($text))); $formula->dessine($size); $v = 1000 - imagesy($formula->image) + $formula->base_verticale + 3; //1000+baseline ($v) is recorded in the name of the image imagepng($formula->image, $dirimg . "/math_" . $v . "_" . $nameimg); } $valign = $v - 1000; $label_text = htmlentities(str_replace('{prime}', "'", $text), ENT_COMPAT, 'UTF-8'); # encode so html stays valid #$label_text = htmlentities(str_replace('{prime}',"'",$text)); # encode so html stays valid $text = str_replace("€", '[euro80]', $text); $text = str_replace("â82ac", '[euroU]', $text); return '<!-- ' . $text . ' --><img src="' . $pathtoimg . "math_" . $v . "_" . $nameimg . '" style="vertical-align:' . $valign . 'px;' . ' display: inline-block ;" alt="' . $label_text . '" title="' . $label_text . '"/>'; }