Esempio n. 1
0
<?php

// resize selected images and tems
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
checkAllocation();
$return = array('error' => false, 'errorText' => '');
$newWidth = $_POST['w'];
$newHeight = $_POST['h'];
include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
$tem = IMAGEBASEDIR . preg_replace('@\\.(jpg|png|gif)$@', '.tem', $_POST['img']);
if (file_exists($tem)) {
    $img = new PsychoMorph_ImageTem($_POST['img']);
} else {
    $img = new PsychoMorph_Image($_POST['img']);
}
if ($newWidth > 0 && $newHeight > 0) {
    // calculate resize dimensions based on exact pixels for both dimensions
    $w = $img->getWidth();
    $h = $img->getHeight();
    $xResize = $newWidth / $w;
    $yResize = $newHeight / $h;
} else {
    if ($newWidth > 0) {
        // calculate resize dimensions based on exact width and same % height
        $w = $img->getWidth();
        $xResize = $newWidth / $w;
        $yResize = $xResize;
    } else {
        if ($newHeight > 0) {
            // calculate resize dimensions based on exact height and same % width
Esempio n. 2
0
 $tmp_name = $_FILES['upload']['tmp_name'][$i];
 $return['file'][$tmp_name] = file_exists($tmp_name);
 $newFileName = safeFileName("{$mydir}/{$name}.{$ext}");
 if ($type[0] == 'image') {
     $tem_name = $name . '.tem';
     $existingtemfile = safeFileName("{$mydir}/{$name}.tem");
     if (!empty($files[$tem_name])) {
         // a tem was uploaded with this image
         $img = new PsychoMorph_ImageTem($tmp_name, $files[$tem_name]);
     } else {
         if (file_exists(IMAGEBASEDIR . $existingtemfile)) {
             // a tem already exists for this image in the user directory
             $img = new PsychoMorph_ImageTem($tmp_name, $existingtemfile);
         } else {
             // there is no tem for this image
             $img = new PsychoMorph_Image($tmp_name);
         }
     }
     $img->setDescription('Uploaded file');
     //$img->save($newFileName);
 } else {
     if ($ext == 'tem') {
         if (!empty($files["{$name}.jpg"])) {
             // a tem file is uploaded with the image
             // already taken care of with the image
             $newFileName = safeFileName("{$mydir}/{$name}.jpg");
         } else {
             if (!empty($files["{$name}.png"])) {
                 $newFileName = safeFileName("{$mydir}/{$name}.png");
             } else {
                 if (!empty($files["{$name}.gif"])) {
Esempio n. 3
0
<?php

// rotate selected images and tems
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
checkAllocation();
$return = array('error' => false, 'errorText' => '');
$degrees = intval($_POST['degrees']) % 360;
$rgb = $_POST['rgb'];
include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
$tem = IMAGEBASEDIR . preg_replace('@\\.(jpg|png|gif)$@', '.tem', $_POST['img']);
if (file_exists($tem)) {
    $img = new PsychoMorph_ImageTem($_POST['img']);
} else {
    $img = new PsychoMorph_Image($_POST['img']);
}
if ($degrees == 0) {
    $return['error'] = true;
    $return['errorText'] = 'No need to rotate 0 degrees.';
}
if (!$return['error']) {
    $img->rotate($degrees, $rgb);
    $newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix'], 'ext' => $_POST['ext']);
    if ($img->save($newFileName)) {
        $return['error'] = false;
        $return['newFileName'] = $img->getURL();
    } else {
        $return['error'] = true;
        $return['errorText'] .= 'The image was not saved. ';
        $return['newFileName'] = '';
    }
Esempio n. 4
0
<?php

// get the LAB colour values from an image
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
$return = array('error' => true, 'errorText' => '');
include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
$theImg = new PsychoMorph_Image($_POST['img']);
if ($image = $theImg->getImage()) {
    $return['width'] = $theImg->getWidth();
    $return['height'] = $theImg->getHeight();
    $return['newFileName'] = preg_replace('/(jpg|gif|png)$/', 'csv', $_POST['img']);
    $filename = IMAGEBASEDIR . $return['newFileName'];
    $filecontents = "x,y,L,a,b\n";
    if ($_POST['ignore_mask'] == 'true') {
        $mask_color = imagecolorat($image, 0, 0);
        $return['ignore_mask'] = $mask_color;
    } else {
        $mask_color = -1;
        $return['ignore_mask'] = $mask_color;
    }
    for ($x = 0; $x < $return['width']; $x++) {
        for ($y = 0; $y < $return['height']; $y++) {
            $color_index = imagecolorat($image, $x, $y);
            if ($color_index != $mask_color) {
                $r = $color_index >> 16 & 0xff;
                $g = $color_index >> 8 & 0xff;
                $b = $color_index & 0xff;
                $lab = rgb2lab($r, $g, $b);
                $l = round($lab['L'], 4);
                $a = round($lab['a'], 4);
Esempio n. 5
0
<?php

// mirror selected images and tems
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';
$tem = IMAGEBASEDIR . preg_replace('@\\.(jpg|png|gif)$@', '.tem', $_POST['img']);
if (file_exists($tem)) {
    $img = new PsychoMorph_ImageTem($_POST['img']);
} else {
    $img = new PsychoMorph_Image($_POST['img']);
}
$img->mirror();
$newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix'], 'ext' => $_POST['ext']);
if ($img->save($newFileName)) {
    $return['error'] = false;
    $return['newFileName'] = $img->getURL();
} else {
    $return['errorText'] .= 'The image was not saved. ';
    $return['newFileName'] = '';
}
scriptReturn($return);
Esempio n. 6
0
<?php

// webcam file save
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';
$newFileName = safeFileName($_POST['basedir'] . '/' . $_POST['name']) . '.jpg';
$return['newFileName'] = $newFileName;
if (!array_key_exists('imgBase64', $_POST)) {
    $return['error'] = true;
    $return['errorText'] .= 'The webcam image did not transfer.';
} else {
    if (file_exists(IMAGEBASEDIR . $newFileName)) {
        $return['error'] = true;
        $return['errorText'] .= preg_replace("/^(\\d{1,11}\\/)/", "/", $newFileName) . ' already exists. Delete, rename, or move it first.';
    } else {
        $img = new PsychoMorph_Image();
        $b64 = str_replace('data:image/jpeg;base64,', '', $_POST['imgBase64']);
        $b64 = str_replace(' ', '+', $b64);
        $img->setImageBase64($b64);
        $img->setDescription('Webcam upload');
        $img->save($newFileName);
    }
}
scriptReturn($return);
exit;
Esempio n. 7
0
                            // copy this image onto the concat image
                            imagecopy($concatimg, $gridimg, $r * $w, $c * $h, 0, 0, $w, $h);
                            imagedestroy($gridimg);
                        } else {
                            // copy this image onto the concat image with resizing
                            imagecopyresampled($concatimg, $gridimg, $r * $w * $scale, $c * $h * $scale, 0, 0, $w * $scale, $h * $scale, $w, $h);
                            imagedestroy($gridimg);
                        }
                    }
                }
            }
        }
        // save concat image
        $newFileName = IMAGEBASEDIR . $project_id . $savedir . '/_grid.jpg';
        $savegrid = imagejpeg($concatimg, $newFileName, 80);
        imagedestroy($concatimg);
        if ($savegrid) {
            include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
            $img = new PsychoMorph_Image($newFileName);
            $img->setDescription(array('concat' => array('top left' => $_POST['topL'], 'top right' => $_POST['topR'], 'bottom left' => $_POST['botL'], 'bottom right' => $_POST['botR'])));
            $img->save($newFileName);
            $return['error'] = false;
        } else {
            $return['errorText'] .= "Grid was not saved.";
        }
        // return concat file name
        $return['newFileName'] = $project_id . $savedir . '/_grid.jpg';
    }
}
scriptReturn($return);
exit;
Esempio n. 8
0
    $source_y = $grids[$k][1] * $gridsize + $y_offset;
    imagecopy($new_image, $original_image, $dest_x, $dest_y, $source_x, $source_y, $gridsize, $gridsize);
}
imagedestroy($original_image);
// superimpose grid on image
if (array_key_exists('line_color', $_POST)) {
    $linecolor = imagecolorallocate($new_image, $_POST['line_color'][0], $_POST['line_color'][1], $_POST['line_color'][2]);
    for ($x = $x_offset; $x <= $imgwidth; $x += $gridsize) {
        imageline($new_image, $x, 0, $x, $imgheight, $linecolor);
    }
    for ($y = $y_offset; $y <= $imgheight; $y += $gridsize) {
        imageline($new_image, 0, $y, $imgwidth, $y, $linecolor);
    }
}
include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
$img = new PsychoMorph_Image($_POST['img']);
$img->setImage($new_image);
foreach ($random_grids as $rg) {
    $scram[] = "{$rg[0]},{$rg[1]}";
}
$desc = array("scramble" => implode(";", $scram), "gridsize" => $gridsize, "offset" => $x_offset . ", " . $y_offset);
if (array_key_exists('line_color', $_POST)) {
    $desc['linecolor'] = $_POST['line_color'][0] . ',' . $_POST['line_color'][1] . ',' . $_POST['line_color'][2];
}
$img->setDescription($desc);
$newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix'], 'ext' => $_POST['ext']);
if ($img->save($newFileName)) {
    $return['error'] = false;
    $return['newFileName'] = $img->getURL();
} else {
    $return['error'] = true;
Esempio n. 9
0
<?php

// align selected images using data from the tems
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/main_func.php';
auth();
checkAllocation();
$return = array('error' => false, 'errorText' => '');
ini_set('memory_limit', '512M');
include_once DOC_ROOT . '/include/classes/psychomorph.class.php';
$img = new PsychoMorph_Image($_POST['img']);
// x, y coordiantes and L*(D65), a*(D65) and b*(D65) values for facelab chart #1
$facelab_chart1 = array('Dark skin' => array(3685, 645, 38.87, 12.15, 12.76), 'Light skin' => array(3685, 855, 64.13, 13.22, 17.01), 'Blue sky' => array(3685, 1065, 51.1, -4.14, -20.63), 'Foliage' => array(3685, 1285, 42.61, -10.89, 21.48), 'Blue flower' => array(3685, 1490, 56.67, 6.91, -23.17), 'Bluish green' => array(3685, 1700, 71.25, -30.38, 2.88), 'Orange' => array(3475, 645, 60.66, 33.49, 53.32), 'Purplish blue' => array(3475, 855, 43.75, 8.59, -41.51), 'Moderate red' => array(3475, 1065, 50.92, 42.18, 13.62), 'Purple' => array(3475, 1285, 31.86, 19.1, -21.07), 'Yellow green' => array(3475, 1490, 71.45, -20.45, 57.14), 'Orange Yellow' => array(3475, 1700, 69.97, 18.5, 64.65000000000001), 'Blue' => array(3265, 645, 33.79, 11.38, -43.55), 'Green' => array(3265, 855, 56.06, -35.2, 32.94), 'Red' => array(3265, 1065, 42.04, 43.83, 25.47), 'Yellow' => array(3265, 1285, 79.78, 4.06, 78.58), 'Magenta' => array(3265, 1490, 52.05, 43.77, -16.57), 'Cyan' => array(3265, 1700, 53.65, -27.77, -22.5), 'White' => array(3055, 645, 95.13, -0.8100000000000001, 2), 'Neutral 8' => array(3055, 855, 81.05, -0.75, 0.09), 'Neutral 6.5' => array(3055, 1065, 66.92, -0.83, -0.36), 'Neutral 5' => array(3055, 1285, 51.33, -0.05, -0.15), 'Neutral 3.5' => array(3055, 1490, 36.27, -0.52, -1.01), 'Black' => array(3055, 1700, 21.99, -0.09, -0.9399999999999999));
$img->colourCalibrate($facelab_chart1);
$newFileName = array('subfolder' => $_POST['subfolder'], 'prefix' => $_POST['prefix'], 'suffix' => $_POST['suffix'], 'ext' => 'jpg');
if ($img->save($newFileName)) {
    $return['error'] = false;
    $return['newFileName'] = $img->getURL();
} else {
    $return['errorText'] .= 'The image was not saved.';
    $return['newFileName'] = '';
}
scriptReturn($return);
exit;