$return = array('error' => false, 'errorText' => ''); include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; if (array_key_exists('imgBase64', $_POST)) { // create image from base64 $newFileName = safeFileName($_POST['basedir'] . '/' . $_POST['name']) . '.jpg'; $img = new PsychoMorph_Image($newFileName); $b64 = str_replace('data:image/jpeg;base64,', '', $_POST['imgBase64']); $b64 = str_replace(' ', '+', $b64); $img->setImageBase64($b64); $img->setDescription('Webcam upload'); } else { if (strpos($_POST['img'], "/.tmp/") !== false) { $tempath = IMAGEBASEDIR . str_replace("/scripts/fileAccess?file=/", "", $_POST['tem']); $imgpath = IMAGEBASEDIR . str_replace("/scripts/fileAccess?file=/", "", $_POST['img']); $newFileName = safeFileName($_POST['name']); $img = new PsychoMorph_ImageTem($imgpath, $tempath); $img->setDescription(json_decode($_POST['desc'])); } else { if (count($_FILES) > 0) { foreach ($_FILES['upload']['tmp_name'] as $i => $tmp_name) { $files[$_FILES['upload']['name'][$i]] = $tmp_name; } $mydir = ''; if (array_key_exists('basedir', $_POST)) { $mydir = str_replace('..', '', $_POST['basedir']); } $imgsaved = array(); for ($i = 0; $i < count($_FILES['upload']['type']); $i++) { $type = explode('/', $_FILES['upload']['type'][$i]); if ($_FILES['upload']['error'][$i] == 0 && $_FILES['upload']['size'][$i] > 0) { // extract file name data
<?php // convert image types require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); checkAllocation(); $return = array('error' => false, 'errorText' => ''); include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $img = new PsychoMorph_ImageTem($_POST['img']); $allowed_ext = array('jpg', 'png', 'gif'); if (in_array($_POST['to'], $allowed_ext)) { if ($img->convert($_POST['to'])) { $return['newFileName'] = $img->getURL(); } else { $return['error'] = true; $return['errorText'] = 'The converted image did not save.'; } } else { $return['error'] = true; $return['errorText'] = $_POST['to'] . ' is not an allowed filetype.'; } scriptReturn($return); exit;
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 6000); $data = curl_exec($ch); curl_close($ch); $pcadata = json_decode($data, true); if (!is_array($pcadata) || !array_key_exists('error', $pcadata) || $pcadata['error'] == 'true') { $return['errorText'] = $data; } else { $return['data'] = $pcadata; if (!empty($pcadata['img'])) { // save image and associated tem include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $avgimg = "/.tmp/" . $pcadata['img']; $avgtem = "/.tmp/" . $pcadata['tem']; $img = new PsychoMorph_ImageTem($avgimg, $avgtem); $img->setDescription(array('Desc' => 'Average image for PCA model ' . $theData['pcafile'] . '.pca', 'images' => $theData['images'], 'texture' => $theData['texture'], 'norm' => 'rigid')); $newFileName = ifEmpty($theData['pcafile'], $theData['pcifile']); if ($img !== null && $img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; $return['newFileName'] = $newFileName; } } } } scriptReturn($return); exit;
curl_setopt($ch, CURLOPT_URL, $url . $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_TIMEOUT, 6000); $data = curl_exec($ch); curl_close($ch); $visdata = json_decode($data, true); if (!array_key_exists('img', $visdata)) { $return['errorText'] .= 'The transform was not created'; } else { // save image and associated tem $return['data'] = $visdata; include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $transimg = $visdata['savefolder'] . $visdata['img']; $transtem = $visdata['savefolder'] . $visdata['tem']; $img = new PsychoMorph_ImageTem($transimg, $transtem); // put the weights back into proportion notation foreach ($visdata['weights'] as $w) { $weights[] = $w / 100; } $img->setDescription(array('PCA model' => $visdata['pcafile'], 'avg' => $visdata['avgfile'], 'PC weights' => "[" . implode(",", $weights) . "]")); $newFileName = $_POST['outname']; if ($img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; } } } scriptReturn($return);
$transdata = json_decode($data, true); if (count($transdata) == 0) { $return['errorText'] .= 'The average was not created'; } else { // log image creation $norm = array("none" => 1, "2point" => 2, "rigid" => 3); $warp = array('multiscale' => 1, 'linear' => 2, 'tps' => 3, 'multiscalerb' => 4); $format = array("jpg" => 1, "gif" => 2, "png" => 3); $imgtype = substr($transdata[0]['images'][0], -3); $avgtype = substr($transdata[0]['img'], -3); $query = sprintf("INSERT INTO avg_log (user_id, n, imgtype, avgtype, width, height, norm, texture, contours, memory, load_time, make_time, dt) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, NOW())", $_SESSION['user_id'], count($transdata[0]['images']), intval($format[$imgtype]), intval($format[$avgtype]), intval($transdata[0]['width']), intval($transdata[0]['height']), intval($norm[$transdata[0]['norm']]), $transdata[0]['texture'] == 'true' ? 1 : 0, $transdata[0]['contours'] == 'true' ? 1 : 0, intval($transdata[0]['memory']), intval($transdata[0]['load-image-time']), intval($transdata[0]['average-time'])); $return['query'] = $query; $q = new myQuery($query); // save image and associated tem $return['data'] = $transdata[0]; include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $transimg = $theData['subfolder'] . '/.tmp/' . $transdata[0]['img']; $transtem = $theData['subfolder'] . '/.tmp/' . $transdata[0]['tem']; $img = new PsychoMorph_ImageTem($transimg, $transtem); $img->setDescription(array('images' => $theData['images0'], 'texture' => $theData['texture0'], 'norm' => $theData['norm0'], 'normpoints' => $theData['normPoint0_0'] . ',' . $theData['normPoint1_0'])); $newFileName = $theData['subfolder'] . $_POST['outname']; if ($img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; $return['newFileName'] = $newFileName; } } scriptReturn($return); exit;
<?php // crop selected images require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); checkAllocation(); $return = array('error' => false, 'errorText' => ''); include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $img = new PsychoMorph_ImageTem($_POST['img']); $t = $_POST['t']; $r = $_POST['r']; $b = $_POST['b']; $l = $_POST['l']; $x = $_POST['x']; $y = $_POST['y']; $w = $_POST['w']; $h = $_POST['h']; $rgb = $_POST['rgb']; if ($t !== '' && $r !== '' && $b !== '' && $l !== '') { $orig_w = $img->getImg()->getWidth(); $orig_h = $img->getImg()->getHeight(); $w = $orig_w + $l + $r; $h = $orig_h + $t + $b; $x = -1 * $l; $y = -1 * $t; } else { if ($x !== '' && $y !== '' && $w !== '' && $h !== '') { // do nothing } else { $return['error'] = true; $return['errorText'] = 'There was not enough information to crop the images.';
<?php // symmetrise selected images and tems require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); checkAllocation(); $return = array('error' => true, 'errorText' => '', 'post' => $_POST); include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $img = new PsychoMorph_ImageTem($_POST['img']); $shape = $_POST['shape'] == 'false' ? 0 : 0.5; $colortex = $_POST['color'] == 'false' ? 0 : 0.5; $img->sym($shape, $colortex); $newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix'], 'name' => pathinfo($_POST['img'], PATHINFO_FILENAME), 'ext' => $_POST['ext']); if ($img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; $return['newFileName'] = ''; } scriptReturn($return); exit;
ini_set('memory_limit', '512M'); // standard 1350 x 1800 FRL alignment $aligned_x1 = $_POST['x1']; $aligned_y1 = $_POST['y1']; $aligned_x2 = $_POST['x2']; $aligned_y2 = $_POST['y2']; $align_width = $_POST['width']; $align_height = $_POST['height']; $align_pt1 = $_POST['pt1']; $align_pt2 = $_POST['pt2']; $rgb = $_POST['rgb']; include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; if (array_key_exists('tem', $_POST)) { $img = new PsychoMorph_ImageTem($img, $_POST['tem']); } else { $img = new PsychoMorph_ImageTem($img); } $img->alignEyes($align_width, $align_height, array($aligned_x1, $aligned_y1), array($aligned_x2, $aligned_y2), $align_pt1, $align_pt2, $rgb); if (array_key_exists('newFileName', $_POST)) { $newFileName = safeFileName($_POST['newFileName']); } else { $newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix']); } //$img->setOverWrite(true); if ($img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; } } else {
curl_close($ch); $transdata = json_decode($data, true); if (count($transdata) == 0) { $return['errorText'] .= 'The transform was not created'; } else { // log image transform $norm = array("none" => 1, "2point" => 2, "rigid" => 3); $warp = array('multiscale' => 1, 'linear' => 2, 'tps' => 3, 'multiscalerb' => 4); $format = array("jpg" => 1, "gif" => 2, "png" => 3); $imgtype = substr($transdata[0]['transimg'], -3); $transtype = substr($transdata[0]['img'], -3); $query = sprintf("INSERT INTO trans_log (user_id, imgtype, transtype, shape, color, texture, width, height, norm, warp, contours, memory, load_time, make_time, dt) VALUES (%d, %d, %d, %f, %f, %f, %d, %d, %d, %d, %d, %d, %d, %d, NOW())", $_SESSION['user_id'], intval($format[$imgtype]), intval($format[$transtype]), floatval(str_replace('%', '', $transdata[0]['shape'])), floatval(str_replace('%', '', $transdata[0]['color'])), floatval(str_replace('%', '', $transdata[0]['texture'])), intval($transdata[0]['width']), intval($transdata[0]['height']), intval($norm[$transdata[0]['norm']]), intval($warp[$transdata[0]['warp']]), $transdata[0]['contours'] == 'true' ? 1 : 0, intval($transdata[0]['memory']), intval($transdata[0]['load-image-time']), intval($transdata[0]['transform-time'])); $return['query'] = $query; $q = new myQuery($query); // save image and associated tem $return['data'] = $transdata[0]; include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $transimg = $theData['subfolder'] . '/.tmp/' . $transdata[0]['img']; $transtem = $theData['subfolder'] . '/.tmp/' . $transdata[0]['tem']; $img = new PsychoMorph_ImageTem($transimg, $transtem); $img->setDescription(array('transimg' => $theData['transimage0'], 'fromimg' => $theData['fromimage0'], 'toimg' => $theData['toimage0'], 'shape' => round($theData['shape0'] * 100, 1) . '%', 'color' => round($theData['color0'] * 100, 1) . '%', 'texture' => round($theData['texture0'] * 100, 1) . '%', 'norm' => $theData['norm0'], 'normpoints' => $theData['normPoint0_0'] . ',' . $theData['normPoint1_0'], 'warp' => $theData['warp0'], 'contour' => $theData['sampleContours0'])); $newFileName = $theData['subfolder'] . $_POST['outname']; if ($img->save($newFileName)) { $return['error'] = false; $return['newFileName'] = $img->getImg()->getURL(); } else { $return['errorText'] .= 'The image was not saved. '; } } scriptReturn($return); exit;
<?php // mask an image require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php'; auth(); checkAllocation(); $return = array('error' => false, 'errorText' => ''); include_once DOC_ROOT . '/include/classes/psychomorph.class.php'; $img = new PsychoMorph_ImageTem($_POST['img']); $mask = explode(',', $_POST['mask']); $custom = null; if (!empty($_POST['custom'])) { $mask = array('custom'); $custom = explode(':', $_POST['custom']); foreach ($custom as $j => $m) { $custom[$j] = explode(';', $m); foreach ($custom[$j] as $i => $m2) { $custom[$j][$i] = explode(',', $m2); } } } $rgba = $_POST['rgb']; $a = $_POST['transparent'] == 'true' ? 0 : 1; array_push($rgba, $a); $blur = $_POST['blur']; if (!$mask || !$rgba) { $return['error'] = true; $return['errorText'] = 'There was not enough information to mask the images.'; } if (!$return['error']) { ini_set('max_execution_time', 30 * ($blur + 1));