Esempio n. 1
0
function images($params)
{
    global $template_file;
    $template_file = '';
    $data = array();
    //
    $data['path'] = implode('/', $params);
    $files_path = STATIC_FILES_ROOT . $data['path'] . '/';
    if (!is_dir($files_path)) {
        mkdir($files_path, 0775, true);
    }
    //
    if (isset($_FILES['file']) && isset($_FILES['file']['tmp_name']) && $_FILES['file']['tmp_name'] != '') {
        include 'interfaces/image_magic.php';
        move_uploaded_file($_FILES['file']['tmp_name'], $files_path . $_FILES['file']['name']);
        $new_name = time() . '.jpg';
        $image = load_image($files_path . $_FILES['file']['name']);
        save_image($image, $files_path . $new_name, 'jpg');
        //
        $thumbnail = thumbnail($image, 160);
        save_image($thumbnail, $files_path . 'thumb_' . $new_name, 'jpg');
        //
        unlink($files_path . $_FILES['file']['name']);
        imagedestroy($image);
        imagedestroy($thumbnail);
    }
    //
    $data['files'] = array();
    if ($dh = opendir($files_path)) {
        while (($file = readdir($dh)) !== false) {
            if ($file == '.' || $file == '..' || is_dir($files_path . '/' . $file)) {
            } else {
                if (substr($file, 0, 6) == 'thumb_') {
                    $filemtime = filemtime($files_path . '/' . $file);
                    $type = strtolower(substr($file, strrpos($file, '.') + 1));
                    $file_size = filesize($files_path . '/' . $file);
                    $data['files'][] = array('type' => $type, 'file_size' => intval($file_size / 10.24) / 100, 'created_at' => $filemtime, 'thumb' => $file, 'name' => substr($file, 6));
                }
            }
        }
        closedir($dh);
    }
    return $data;
}
Esempio n. 2
0
function node_image($metrics)
{
    global $hosts_down;
    # More rigorous checking if variables are set before trying to use them.
    if (isset($metrics['cpu_num']['VAL']) and $metrics['cpu_num']['VAL'] != 0) {
        $cpu_num = $metrics['cpu_num']['VAL'];
    } else {
        $cpu_num = 1;
    }
    if (isset($metrics['load_one']['VAL'])) {
        $load_one = $metrics['load_one']['VAL'];
    } else {
        $load_one = 0;
    }
    $value = $load_one / $cpu_num;
    # Check if the host is down
    # RFM - Added isset() check to eliminate error messages in ssl_error_log
    if (isset($hosts_down) and $hosts_down) {
        $image = template("images/node_dead.jpg");
    } else {
        $image = load_image("node", $value);
    }
    return $image;
}
Esempio n. 3
0
$filepath = "fullcolor.jpg";
//比較対象用画像ディレクトリ
$dir = "images/";
$sample = load_image($filepath);
$sample_lab = image_lab($sample);
imagedestroy($sample);
$list = scandir($dir);
$files = array();
foreach ($list as $value) {
    if (is_file($dir . $value)) {
        $files[] = $dir . $value;
    }
}
$diff = array();
foreach ($files as $file) {
    $image = load_image($file);
    $lab = image_lab($image);
    imagedestroy($image);
    $distance = 0;
    foreach ($sample_lab as $key => $value) {
        $distance += lab_distance($value, $lab[$key]);
    }
    $name = basename($file);
    $diff[$name] = $distance;
    //    $diff[1][] = $distance;
    //    $diff[2][] = $name;
}
//asort($diff);
$index = 0;
foreach ($diff as $distance) {
    echo $index . "-" . $distance . "              ";
Esempio n. 4
0
/**
 * Rotate image
 *
 * @param object File
 * @param integer # degrees to rotate
 * @return boolean TRUE if rotating is successful
 */
function rotate_image($File, $degrees)
{
    $Filetype =& $File->get_Filetype();
    if (!$Filetype) {
        // Error
        return false;
    }
    // Load image
    list($err, $imh) = load_image($File->get_full_path(), $Filetype->mimetype);
    if (!empty($err)) {
        // Error
        return false;
    }
    // Rotate image
    if (!($imh = @imagerotate($imh, (int) $degrees, 0))) {
        // If func imagerorate is not defined for example:
        return false;
    }
    // Save image
    save_image($imh, $File->get_full_path(), $Filetype->mimetype);
    // Remove the old thumbnails
    $File->rm_cache();
    return true;
}
Esempio n. 5
0
     if ($c == $self) {
         continue;
     }
     if ($c == "AAAAA.{$self}") {
         continue;
     }
     # SORT HACK; see above
     if (isset($private[$c]) and $private[$c]) {
         $Private[$c] = template("images/cluster_private.jpg");
         continue;
     }
     $names[] = $c;
     if (isset($grid[$c]['GRID']) and $grid[$c]['GRID']) {
         $image = load_image("grid", $values[$c]);
     } else {
         $image = load_image("cluster", $values[$c]);
     }
     $Images[] = $image;
 }
 # Add private cluster pictures to the end.
 if (isset($Private) and is_array($Private)) {
     foreach ($Private as $c => $image) {
         $names[] = $c;
         $Images[] = $image;
     }
 }
 # All this fancyness is to get the Cluster names
 # above the image. Not easy with template blocks.
 $cols = 5;
 $i = 0;
 $count = count($names);
Esempio n. 6
0
$title->setReadOnly(true);
$desc = new InputText(300);
$desc->setClass("attributeTextGray");
$desc->setReadOnly(true);
$desc->setAutoGrow(true);
$price = new InputText(10);
$price->setClass("inputTextPrice");
$price->setReadOnly(true);
$stock = new InputText();
$stock->setClass("input.textStock");
$stock->setReadOnly(true);
$grid = new HorizontalGrid();
$grid->setRowsPerPagePortrait(1);
$grid->setShowPageController(true);
//$grid -> setPageControllerBackColor("#FFFFFF");
$grid->addData(load_image());
//$grid -> onTap(view_image());
$grid->setPageControllerClass("table.grid");
$table_grid = new Table();
$table_grid->setRowsStyle("100%");
$table_grid->setHeight("100%");
$table_grid->setClass("table.grid");
$image = new InputImage();
$image->setClass("imageImageList");
$table_grid->addControl($image, 1, 1);
$grid->addControl($table_grid, 1, 1);
$btnAdd = new Button();
$btnAdd->setClass("buttonred");
$btnAdd->setCaption("Add to Cart");
$btnAdd->onTap(add_cart());
$tableButtons = new Table();
Esempio n. 7
0
header("Content-type: text/html;charset=utf-8");
$origin_filepath = "fullcolor.jpg";
$sample = load_image($origin_filepath);
$sample_lab = image_lab($sample);
imagedestroy($sample);
if (isset($_POST['upload'])) {
    foreach ($_FILES['files']['tmp_name'] as $key => $name_tmp) {
        $name = $_FILES['files']['name'][$key];
        $tmp_name = $_FILES['files']['tmp_name'][$key];
        $type = $_FILES['files']['type'][$key];
        $size = $_FILES['files']['size'][$key];
        $dir = "uploads/";
        $filepath = $dir . $name;
        $moveResult = move_uploaded_file($tmp_name, $filepath);
        if ($moveResult) {
            $image = load_image($filepath);
            $lab = image_lab($image);
            $distance = 0;
            foreach ($sample_lab as $key => $value) {
                $distance += lab_distance($value, $lab[$key]);
            }
            $sqlCheck = "SELECT * FROM imageInfo WHERE ABS(distance - {$distance}) <= 5";
            if ($conn->query($sqlCheck)) {
                $result = $conn->query($sqlCheck);
                if ($result->num_rows > 0) {
                    echo "<script>alert('File existed!')</script>";
                } else {
                    $sqlInsert = "INSERT INTO imageInfo(path, type, size, distance) VALUES ('{$filepath}','{$type}','{$size}','{$distance}')";
                    if ($conn->query($sqlInsert)) {
                        echo "<script>alert('Insert to db sucessful')</script>";
                    } else {
Esempio n. 8
0
             }
             $image_type = 'png';
             $img['mime'] = 'image/png';
             $output_type = 'png';
             break;
         default:
             ErrorPNG($ERR_710);
             exit;
     }
 } else {
     ErrorPNG($ERR_710);
     exit;
 }
 if ($w == '') {
     // just load the image
     load_image($fromfile, $img['mime'], $image_type, $output_type);
 } else {
     // check image orientation
     if ($img[0] < $img[1]) {
         $h = $w;
         $ratio = floatval($img[1] / $h);
         $w = ceil($img[0] / $ratio);
     } else {
         $ratio = floatval($img[0] / $w);
         $h = ceil($img[1] / $ratio);
     }
     $ou = imagecreatetruecolor($w, $h);
     imagealphablending($ou, false);
     $funcall = "imagecreatefrom{$image_type}";
     imagecopyresampled($ou, $funcall($fromfile), 0, 0, 0, 0, $w, $h, $img[0], $img[1]);
     $funcall = "image{$output_type}";
Esempio n. 9
0
File: save.php Progetto: p4-team/ctf
<?php

include 'common.php';
if (empty($_POST['imagekey'])) {
    header('Location: ?op=home');
    exit;
}
$imagekey = $_POST['imagekey'];
$im = load_image($imagekey);
$w = imagesx($im);
$h = imagesy($im);
if ($w > MAX_IM_SIZE || $h > MAX_IM_SIZE) {
    fatal("Invalid image dimensions.");
}
$nc = imagecolorstotal($im);
if ($nc == 0 || $nc > 256) {
    fatal("Invalid palette size.");
}
$data = json_decode($_POST['savedata'], true);
if ($data === null) {
    fatal("Invalid JSON data.");
}
if (!is_array($data['pal']) || !is_array($data['im'])) {
    fatal("Bad data.");
}
$newpal = $data['pal'];
$newim = $data['im'];
if (count($newpal) > 256 || count($newim) != $w * $h) {
    fatal("Bad data.");
}
for ($i = 0; $i < count($newpal); $i++) {
Esempio n. 10
0
/**
 * Prepare image file (Resize, Rotate and etc.)
 *
 * @param object File
 * @param string mimetype
 */
function prepare_uploaded_image($File, $mimetype)
{
    global $Settings, $Messages;
    $thumb_width = $Settings->get('fm_resize_width');
    $thumb_height = $Settings->get('fm_resize_height');
    $thumb_quality = $Settings->get('fm_resize_quality');
    $do_resize = false;
    if ($Settings->get('fm_resize_enable') && $thumb_width > 0 && $thumb_height > 0) {
        // Image resizing is enabled
        list($image_width, $image_height) = explode('x', $File->get_image_size());
        if ($image_width > $thumb_width || $image_height > $thumb_height) {
            // This image should be resized
            $do_resize = true;
        }
    }
    load_funcs('files/model/_image.funcs.php');
    $resized_imh = null;
    if ($do_resize) {
        // Resize image
        list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
        if (empty($err)) {
            list($err, $resized_imh) = generate_thumb($src_imh, 'fit', $thumb_width, $thumb_height);
        }
        if (empty($err)) {
            // Image was rezised successfully
            $Messages->add(sprintf(T_('%s was resized to %dx%d pixels.'), '<b>' . $File->get('name') . '</b>', imagesx($resized_imh), imagesy($resized_imh)), 'success');
        } else {
            // Image was not rezised
            $Messages->add(sprintf(T_('%s could not be resized to target resolution of %dx%d pixels.'), '<b>' . $File->get('name') . '</b>', $thumb_width, $thumb_height), 'error');
            // Error exists, exit here
            return;
        }
    }
    if ($mimetype == 'image/jpeg') {
        // JPEG, do autorotate if EXIF Orientation tag is defined
        $save_image = !$do_resize;
        // If image was be resized, we should save file only in the end of this function
        exif_orientation($File->get_full_path(), $resized_imh, $save_image);
    }
    if (!$resized_imh) {
        // Image resource is incorrect
        return;
    }
    if ($do_resize && empty($err)) {
        // Save resized image ( and also rotated image if this operation was done )
        save_image($resized_imh, $File->get_full_path(), $mimetype, $thumb_quality);
    }
}
Esempio n. 11
0
/**
 * Prepare image file (Resize, Rotate and etc.)
 *
 * @param object File
 * @param string mimetype
 */
function prepare_uploaded_image($File, $mimetype)
{
    global $Settings;
    $thumb_width = $Settings->get('fm_resize_width');
    $thumb_height = $Settings->get('fm_resize_height');
    $thumb_quality = $Settings->get('fm_resize_quality');
    $do_resize = false;
    if ($Settings->get('fm_resize_enable') && $thumb_width > 0 && $thumb_height > 0) {
        // Image resizing is enabled
        list($image_width, $image_height) = explode('x', $File->get_image_size());
        if ($image_width > $thumb_width || $image_height > $thumb_height) {
            // This image should be resized
            $do_resize = true;
        }
    }
    load_funcs('files/model/_image.funcs.php');
    $resized_imh = null;
    if ($do_resize) {
        // Resize image
        list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
        if (empty($err)) {
            list($err, $resized_imh) = generate_thumb($src_imh, 'fit', $thumb_width, $thumb_height);
        }
    }
    if (!empty($err)) {
        // Error exists, Exit here
        return;
    }
    if ($mimetype == 'image/jpeg') {
        // JPEG, do autorotate if EXIF Orientation tag is defined
        $save_image = !$do_resize;
        // If image was be resized, we should save file only in the end of this function
        exif_orientation($File->get_full_path(), $resized_imh, $save_image);
    }
    if (!$resized_imh) {
        // Image resource is incorrect
        return;
    }
    if ($do_resize && empty($err)) {
        // Save resized image ( and also rotated image if this operation was done )
        save_image($resized_imh, $File->get_full_path(), $mimetype, $thumb_quality);
    }
}
Esempio n. 12
0
/**
 * Crop image
 *
 * @param object File
 * @param integer X coordinate (in percents)
 * @param integer Y coordinate (in percents)
 * @param integer Width (in percents)
 * @param integer Height (in percents)
 * @param integer Min size of width or height (in pixels), 0 - to don't limit
 * @param integer Max size of width or height (in pixels), 0 - to don't limit
 * @return boolean TRUE if cropping is successful
 */
function crop_image($File, $x, $y, $width, $height, $min_size = 0, $max_size = 0)
{
    $Filetype =& $File->get_Filetype();
    if (!$Filetype) {
        // Error
        return false;
    }
    // Load image
    list($err, $src_imh) = load_image($File->get_full_path(), $Filetype->mimetype);
    if (!empty($err)) {
        // Error
        return false;
    }
    $src_width = imagesx($src_imh);
    $src_height = imagesy($src_imh);
    $x = $src_width * ($x / 100);
    $y = $src_height * ($y / 100);
    $width = $src_width * ($width / 100);
    $height = $src_height * ($height / 100);
    $dest_width = $width;
    $dest_height = $height;
    if ($max_size > 0) {
        // Check if we should limit by max size
        $dest_width = $dest_width > $max_size ? $max_size : $dest_width;
        $dest_height = $dest_height > $max_size ? $max_size : $dest_height;
    }
    if ($min_size > 0) {
        // Check if we should limit by min size
        $width = $width < $min_size ? $min_size : $width;
        $height = $height < $min_size ? $min_size : $height;
    }
    if ($x + $width > $src_width) {
        // Shift a crop X position to the left if the crop width is over image width
        $x = $src_width - $width;
    }
    if ($y + $height > $src_height) {
        // Shift a crop Y position to the top if the crop height is over image height
        $y = $src_height - $height;
    }
    $dst_imh = imagecreatetruecolor($dest_width, $dest_height);
    // Crop image
    if (!@imagecopyresampled($dst_imh, $src_imh, 0, 0, $x, $y, $dest_width, $dest_height, $width, $height)) {
        // If func imagecopyresampled is not defined for example:
        return false;
    }
    // Save image
    save_image($dst_imh, $File->get_full_path(), $Filetype->mimetype);
    // Remove the old thumbnails
    $File->rm_cache();
    return true;
}
Esempio n. 13
0
 /**
  * Expand image to a square
  *
  * @param object File
  * @return boolean
  */
 function userimg_expand_to_square(&$File)
 {
     if (!$File->is_image()) {
         // This must be an image:
         return false;
     }
     $Filetype =& $File->get_Filetype();
     if (!$Filetype) {
         // File type must be, otherwise we cannot work with this file:
         return false;
     }
     // Get image size:
     $image_size = $File->get_image_size('widthheight_assoc');
     if ($image_size['width'] == $image_size['height']) {
         // We should not expand this image because it is already a square:
         return false;
     }
     load_funcs('files/model/_image.funcs.php');
     // Load image:
     list($err, $src_imh) = load_image($File->get_full_path(), $Filetype->mimetype);
     if (!empty($err)) {
         // Error on image loading:
         return false;
     }
     // Expand image to square ---- START:
     // Use max side as square size for width & height:
     $expanded_image_size = max($image_size);
     if ($image_size['width'] > $image_size['height']) {
         // If width is more than height then we should center image vertically:
         $dst_x = 0;
         $dst_y = ceil(($expanded_image_size - $image_size['height']) / 2);
     } else {
         // If width is less than height then we should center image horizonatally:
         $dst_x = ceil(($expanded_image_size - $image_size['width']) / 2);
         $dst_y = 0;
     }
     // Create canvas for new image with white background:
     $dst_imh = imagecreatetruecolor($expanded_image_size, $expanded_image_size);
     $white_color = imagecolorallocate($dst_imh, 255, 255, 255);
     imagefill($dst_imh, 0, 0, $white_color);
     if (!@imagecopyresampled($dst_imh, $src_imh, $dst_x, $dst_y, 0, 0, $image_size['width'], $image_size['height'], $image_size['width'], $image_size['height'])) {
         // If func imagecopyresampled is not defined for example:
         return false;
     }
     // Expand image to square ---- END.
     // Save image:
     save_image($dst_imh, $File->get_full_path(), $Filetype->mimetype);
     // Remove the old thumbnails:
     $File->rm_cache();
     return true;
 }
Esempio n. 14
0
    $fd = fopen($dir . $_FILES["image_to_load"]["name"][0], "r");
    $md1 = $dbxClient->uploadFile("/" . $_SESSION["user"] . "/" . $_FILES[image_to_load][name][0], \Dropbox\WriteMode::add(), $fd);
    fclose($fd);
    print "db answer: ";
    print_r($md1);
    return TRUE;
}
if (is_empty_file($image) == TRUE) {
    print "if \n";
    header("Location: UserPlace.php?CheckResult=EmptyField");
    exit;
} else {
    print "else \n";
    if (check_type($image) == TRUE) {
        if (isExist($image) == TRUE) {
            header("Location: UserPlace.php?CheckResult=Name already exist");
            exit;
        } else {
            print "to load";
            load_image($image);
            header("Location: UserPlace.php?CheckResult=Ok");
            exit;
        }
    } else {
        header("Location: UserPlace.php?CheckResult=Bad format");
        exit;
    }
}
?>
   
Esempio n. 15
0
 if ($err == '!Thumbnail not found in' . $Settings->get('evocache_foldername')) {
     // The thumbnail wasn't already in the cache, try to generate and cache it now:
     $err = NULL;
     // Short error code
     list($src_width, $src_height) = imgsize($File->get_full_path());
     if (!$resample_all_images && check_thumbnail_sizes($thumb_type, $thumb_width, $thumb_height, $src_width, $src_height)) {
         // There is no need to resample, use original!
         $err = $File->get_af_thumb_path($size_name, $mimetype, true, $size_x);
         if ($err[0] != '!' && @copy($File->get_full_path(), $err)) {
             // File was saved. Ouput that same file immediately:
             // note: @copy returns FALSE on failure, if not muted it'll print the error on screen
             $err = $File->output_cached_thumb($size_name, $mimetype, $mtime, $size_x);
         }
     } else {
         // Resample
         list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
         if (empty($err)) {
             list($err, $dest_imh) = generate_thumb($src_imh, $thumb_type, $thumb_width, $thumb_height, $thumb_percent_blur, $size_x);
             if (empty($err)) {
                 $err = $File->save_thumb_to_cache($dest_imh, $size_name, $mimetype, $thumb_quality, $size_x);
                 if (empty($err)) {
                     // File was saved. Ouput that same file immediately:
                     // This is probably better than recompressing the memory image..
                     $err = $File->output_cached_thumb($size_name, $mimetype, $mtime, $size_x);
                 } else {
                     // File could not be saved.
                     // fp> We might want to output dynamically...
                     // $err = output_image( $dest_imh, $mimetype );
                 }
             }
         }
Esempio n. 16
0
 /**
  * This will spit out a content-type header followed by a thumbnail for this file.
  *
  * @todo a million things (fp) but you get the idea...
  * The generated thumb will be saved to a cached file here (fp)
  * The cache will be accessed through the File object (fp)
  * @todo cleanup memory resources
  *
  * @param string requested size: 'thumbnail'
  */
 function thumbnail($req_size)
 {
     load_funcs('/files/model/_image.funcs.php');
     $size_name = $req_size;
     switch ($req_size) {
         case 'fit-720x500':
             $thumb_width = 720;
             $thumb_height = 500;
             $thumb_quality = 90;
             break;
         case 'fit-640x480':
             $thumb_width = 640;
             $thumb_height = 480;
             $thumb_quality = 90;
             break;
         case 'fit-400x320':
             $thumb_width = 400;
             $thumb_height = 320;
             $thumb_quality = 85;
             break;
         case 'fit-320x320':
             $thumb_width = 320;
             $thumb_height = 320;
             $thumb_quality = 85;
             break;
         case 'fit-80x80':
         default:
             $size_name = 'fit-80x80';
             $thumb_width = 80;
             $thumb_height = 80;
             $thumb_quality = 75;
     }
     $mimetype = $this->Filetype->mimetype;
     // Try to output the cached thumbnail:
     $err = $this->output_cached_thumb($size_name, $mimetype);
     if ($err == '!Thumbnail not found in .evocache') {
         // The thumbnail wasn't already in the cache, try to generate and cache it now:
         $err = NULL;
         // Short error code
         list($err, $src_imh) = load_image($this->get_full_path(), $mimetype);
         if (empty($err)) {
             list($err, $dest_imh) = generate_thumb($src_imh, $thumb_width, $thumb_height);
             if (empty($err)) {
                 $err = $this->save_thumb_to_cache($dest_imh, $size_name, $mimetype, $thumb_quality);
                 if (empty($err)) {
                     // File was saved. Ouput that same file immediately:
                     // This is probably better than recompressing the memory image..
                     $err = $this->output_cached_thumb($size_name, $mimetype);
                 } else {
                     // File could not be saved.
                     // fp> We might want to output dynamically...
                     // $err = output_image( $dest_imh, $mimetype );
                 }
             }
         }
     }
     // ERROR IMAGE
     if (!empty($err)) {
         // Generate an error image and try to squeeze an error message inside:
         // Note: we write small and close to the upper left in order to have as much text as possible on small thumbs
         $err = substr($err, 1);
         // crop 1st car
         $car_width = ceil(($thumb_width - 4) / 6);
         // $err = 'w='.$car_width.' '.$err;
         $err = wordwrap($err, $car_width, "\n");
         $err = split("\n", $err);
         // split into lines
         $im_handle = imagecreatetruecolor($thumb_width, $thumb_height);
         // Create a black image
         $text_color = imagecolorallocate($im_handle, 255, 0, 0);
         $y = 0;
         foreach ($err as $err_string) {
             imagestring($im_handle, 2, 2, $y, $err_string, $text_color);
             $y += 11;
         }
         header('Content-type: image/png');
         imagepng($im_handle);
     }
 }