示例#1
0
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
                    $ext = pathinfo($_FILES['upload']['name'][$i], PATHINFO_EXTENSION);
示例#2
0
    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;
示例#3
0
    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);
exit;
示例#4
0
$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;
示例#5
0
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;