I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Products » LaTeX Equation Editor »

CodeCogs\′s Photo
12 Jul 11, 7:25PM
If you want to cache images, then you need access to the backend server technology (most often PHP or ASP). You can then make the same request as above, but within PHP and therefore extract from the JSON data

The following should achieve what you need. There is (somewhere) another forum post on much the same:

function latexEqn_json($latex_formula, $font_size='normal', $dpi=110, $local=NULL)
{
  // don't waste CodeCogs time if you've nothing to request. 
  $latex_formula=trim(str_replace("\n",' ',$latex_formula));
	if(empty($latex_formula)) return;
 
	$url='';
	if($font_size!='normal') $url.='\\'.$this->font_size.' ';
	if($dpi!=110) $url.='\\'.$dpi.'dpi ';
	$url.=$latex_formula;
 
	// encode the url so its safe for transmittion to codecogs
	$url=LLATEX_ENGINE.(str_replace(array('+',' '),array('+','&space;'), $url));
 
	// tell CodeCogs who you are - you must keep this line in
	ini_set('user_agent', "PHP\r\nReferer: http://".$_SERVER['SERVER_NAME']);
	$json=file_get_contents($url); // the return will be in the form: ParseEqn({ ... }); So need to
trim this down.
 
	$object=json_decode(substr($json,9,strlen($json)-11));
 
	if($local!==NULL)
	{
		if(!isset($object->latex->error) && isset($object->latex->file))
		{
		  if(!isset($object->latex->local)) 	// then move from remote server to local machine
			{
				copy($object->latex->url, $_SERVER['DOCUMENT_ROOT'].$local.$object->latex->file);
			}
			else
			{
			  // otherwise this is on a codecogs machine 
				//this option isn't normally available for clients, so hard coded paths can be ignored.
				copy('/var/www/html/'.$object->latex->local,
$_SERVER['DOCUMENT_ROOT'].$local.$object->latex->file);
			}
		  $object->latex->local=$local.$object->latex->file;
		}
		else error_log($object->latex->error);
	}
	return <div class="orangebox">[$]</div>object;
}
Currently you need to be logged in to leave a message.