"", 'magstep' => TexToPng_magstep, 'img' => 'png', 'subslash' => 'off', 'antialias' => TexToPng_antialias ? 'on' : 'off', 'transparent' => TexToPng_transparent ? 'on' : 'off', 'center' => 'off'); } function getImage($dbi, $argarray, $request) { extract($argarray); $this->checkParams($tex, $magstep, $subslash, $antialias, $transparent); return $this->TexToImg($tex, $magstep, $antialias, $transparent); } // run function getExpire($dbi, $argarray, $request) { return '0'; } function getImageType($dbi, $argarray, $request) { extract($argarray); return $img; } function getAlt($dbi, $argarray, $request) { extract($argarray); return $tex; } function embedImg($url,$dbi,$argarray,$request) { $html = HTML::img( array( 'src' => $url, 'alt' => htmlspecialchars($this->getAlt($dbi,$argarray,$request)) )); if ($argarray['center']=='on') return HTML::div( array('style' => 'text-align:center;'), $html); return $html; } /* -------------------- error handling ---------------------------- */ function dbg( $out ) { // test if verbose debug info is selected if (TexToPng_debug) { $this->complain( $out."\n" ); } else { if (!$this->_errortext) { // yeah, I've been told to be quiet, but obviously // an error occured. So at least complain silently. $this->complain(' '); } } } // dbg /* -------------------- parameter handling ------------------------ */ function helptext() { $aa= TexToPng_antialias ?'on(default)$|$off':'on$|$off(default)'; $tp= TexToPng_transparent?'on(default)$|$off':'on$|$off(default)'; $help = '/settabs/+/indent&$<$?plugin /bf{Tex} & [{/tt transparent}] & = "png(default)$|$jpeg$|$gif"& /cr'."\n". '/+&$<$?plugin /bf{TexToPng} & /hfill {/tt tex} & = "/TeX/ commands"& /cr'."\n". '/+& & /hfill [{/tt img}] & = "png(default)$|$jpeg$|$gif"& /cr'."\n". '/+& & /hfill [{/tt magstep}] & = "0 to 5 ('.TexToPng_magstep.' default)"& /cr'."\n". '/+& & /hfill [{/tt center}] & = "on$|$off(default)"& /cr'."\n". '/+& & /hfill [{/tt subslash}] & = "on$|$off(default)"& /cr'."\n". '/+& & /hfill [{/tt antialias}] & = "'.$aa.'"& /cr'."\n". '/+& & /hfill [{/tt transparent}] & = "'.$tp.'"&?$>$ /cr'."\n"; return strtr($help, '/', '\\' ); } // helptext function checkParams( &$tex, &$magstep, $subslash, &$aalias, &$transp ) { if ($subslash=='on') { // WORKAROUND for backslashes $tex = strtr($tex,'/','\\'); } // ------- check parameters $def = $this->getDefaultArguments(); if ($tex=='') { $tex = $this->helptext(); } if ($magstep < 0 || $magstep > 5 ) { $magstep = $def["magstep"]; } // calculate magnification factor $magstep = floor(10*pow(1.2,$magstep))/10; $aalias = $aalias != 'off'; $transp = $transp != 'off'; } // checkParams /* ------------------ image creation ------------------------------ */ function execute($cmd,$complainvisibly=false) { exec($cmd, $errortxt, $returnval); $ok = $returnval == 0; if (!$ok) { if (!$complainvisibly) { $this->dbg('Error during execution of '.$cmd ); }; while (list($key,$value)=each($errortxt)) { if ($complainvisibly) { $this->complain( $value."\n" ); } else { $this->dbg( $value ); } } } return $ok; } // execute /* ---------------------------------------------------------------- */ function createTexFile($texfile,$texstr) { if ($ok=($fp=fopen($texfile, 'w'))!=0 ) { // prepare .tex file $texcommands = '\nopagenumbers' . "\n" . '\hoffset=0cm' . "\n" . '\voffset=0cm' . "\n" . // '\hsize=20cm' . "\n" . // '\vsize=10ex' . "\n" . $texstr . "\n" . '\vfill\eject' . "\n" . '\end' . "\n\n"; $ok = fwrite($fp, $texcommands); $ok = fclose($fp) && $ok; // close anyway } if (!$ok) { $this->dbg('could not write .tex file: ' . $texstr); } return $ok; } // createTexFile /* ---------------------------------------------------------------- */ function TexToImg($texstr, $scale, $aalias, $transp) { //$cacheparams = $GLOBALS['CacheParams']; $tempfiles = $this->tempnam('TexToPng'); $img = 0; // $size = 0; // procuce options for pstoimg $options = ($aalias ? '-aaliastext -color 8 ' : '-color 1 ') . ($transp ? '-transparent ' : '') . '-scale ' . $scale . ' ' . '-type png -crop btlr -geometry 600x150 -margins 0,0'; // rely on intelligent bool interpretation $ok= $tempfiles && $this->createTexFile($tempfiles.'.tex',$texstr) && $this->execute('cd '.$cacheparams['cache_dir'].'; '. "$texbin ".$tempfiles.'.tex',true) && $this->execute("$dvipsbin -o".$tempfiles.'.ps '.$tempfiles.'.dvi') && $this->execute("$pstoimgbin $options" .' -out '.$tempfiles.'.png '. $tempfiles.'.ps' ) && file_exists( $tempfiles.'.png' ); if ($ok) { if (!($img = ImageCreateFromPNG( $tempfiles.'.png' ))) { $this->dbg("Could not open just created image file: $tempfiles"); $ok = false; } } // clean up tmpdir; in debug mode only if no error occured if ( !TexToPng_debug || (TexToPng_debug && $ok)) { if ($tempfiles) { unlink($tempfiles); unlink($tempfiles . '.ps'); unlink($tempfiles . '.tex'); //unlink($tempfiles . '.aux'); unlink($tempfiles . '.dvi'); unlink($tempfiles . '.log'); unlink($tempfiles . '.png'); } } if ($ok) { return $img; } return false; } // TexToImg } // WikiPlugin_TexToPng // For emacs users // Local Variables: // mode: php // tab-width: 4 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>