PHP Classes

File: ajax/ajax.draw.php

Recommend this page to a friend!
  Classes of Johan Barbier   PHP Draw   ajax/ajax.draw.php   Download  
File: ajax/ajax.draw.php
Role: Example script
Content type: text/plain
Description: Ajax script
Class: PHP Draw
Render an image using drawing command language
Author: By
Last change: Automated creation of the temporary repository folder for images
Date: 16 years ago
Size: 1,839 bytes
 

Contents

Class file image Download
<?php
require_once '../inc/inc.main.php';
header('Content-type: text/xml');

if(isset(
$_POST['EXPR'])) {
    try {
        if(!empty(
$_POST['FILE'])) {
           
$oInterpreter = new interpreter('../'.$_POST['FILE']);
        } else {
           
$oInterpreter = new interpreter;
        }
       
        if(!
is_dir('../tmpimg')) {
           
mkdir('../tmpimg', 0755);
        }
       
$aDir = scandir('../tmpimg');
       
$aDir = array_diff($aDir, array('.', '..'));
        foreach(
$aDir as $sToBeDeleted) {
           
unlink('../tmpimg/'.$sToBeDeleted);
        }
       
       
$sFile = uniqid().'.png';
       
       
$oInterpreter->X = (int)$_POST['X'];
       
$oInterpreter->Y = (int)$_POST['Y'];
       
$oInterpreter->COLOR = $_POST['COLOR'];
       
$oInterpreter->PIXEL = (int)$_POST['PIXEL'];
       
$oInterpreter->FONTSIZE = (int)$_POST['FONTSIZE'];
       
$oInterpreter->interpret($_POST['EXPR']);
       
$oInterpreter->getSavedMove('../tmpimg/'.$sFile);
       
$oDom = new DOMDocument('1.0', 'iso-8859-1');
       
$oRoot = $oDom->createElement('phpdraw');
       
$oDom->appendChild($oRoot);
       
$oFile = $oDom->createElement('file', substr('../tmpimg/'.$sFile, 3));
       
$oX = $oDom->createElement('x', $oInterpreter->X);
       
$oY = $oDom->createElement('y', $oInterpreter->Y);
       
$oColor = $oDom->createElement('color', $oInterpreter->COLOR);
       
$oThickNess = $oDom->createElement('thickness', $oInterpreter->PIXEL);
       
$oFontSize = $oDom->createElement('fontsize', $oInterpreter->FONTSIZE);
       
$oRoot->appendChild($oFile);
       
$oRoot->appendChild($oX);
       
$oRoot->appendChild($oY);
       
$oRoot->appendChild($oColor);
       
$oRoot->appendChild($oThickNess);
       
$oRoot->appendChild($oFontSize);
       
        echo
utf8_decode($oDom->saveXML());
    } catch(
Exception $e) {
       
$oDom = new DOMDocument('1.0', 'iso-8859-1');
       
$oRoot = $oDom->createElement('phpdraw');
       
$oDom->appendChild($oRoot);
       
$oErr = $oDom->createElement('error', $e);
       
$oRoot->appendChild($oErr);
       
        echo
utf8_decode($oDom->saveXML());
    }
}
?>