Ejemplo n.º 1
0
}
//apply the file path
$file_src_new = $file_path . '/' . $file_name;
//Chmod the folder
//$CORE->ChmodWritable($file_path);
//we've got no error
$error = false;
$objImage = new ImageManipulation($file_src);
if ($objImage->imageok) {
    $objImage->setJpegQuality(100);
    $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
    if ($resize) {
        if ($imageInfo[0] > $resize or $imageInfo[0] < $resize) {
            $objImage->resize($resize);
        }
    }
    //$objImage->show();
    $objImage->save($file_src_new);
    @unlink($file_src);
} else {
    $error = '@AjaxError@Epic Fail. Please contact the administration.';
}
//check for website failure
if ($error) {
    echo $error;
    die;
}
//Chmod the folder back to normal
//$CORE->ChmodReadonly($file_path);
echo $file_name;
exit;
Ejemplo n.º 2
0
    $subPath = tsl($subPath);
}
$src = strippath($_GET['i']);
$thumb_folder = GSTHUMBNAILPATH . $subPath;
$src_folder = '../data/uploads/';
$thumb_folder_rel = '../data/thumbs/' . $subPath;
if (!is_file($src_folder . $subPath . $src)) {
    redirect("upload.php");
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    require_once 'inc/imagemanipulation.php';
    $objImage = new ImageManipulation($src_folder . $subPath . $src);
    if ($objImage->imageok) {
        $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
        //$objImage->show();
        $objImage->save($thumb_folder . 'thumbnail.' . $src);
        $success = i18n_r('THUMB_SAVED');
    } else {
        i18n('ERROR');
    }
}
list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize($src_folder . $subPath . $src);
if (file_exists($thumb_folder . 'thumbnail.' . $src)) {
    list($thwidth, $thheight, $thtype, $athttr) = getimagesize($thumb_folder . 'thumbnail.' . $src);
    $thumb_exists = ' &nbsp; | &nbsp; <a href="' . $thumb_folder_rel . 'thumbnail.' . rawurlencode($src) . '" rel="facybox_i" >' . i18n_r('CURRENT_THUMBNAIL') . '</a> <code>' . $thwidth . 'x' . $thheight . '</code>';
} else {
    require_once 'inc/imagemanipulation.php';
    genStdThumb($subPath, $src);
    list($thwidth, $thheight, $thtype, $athttr) = getimagesize($thumb_folder . 'thumbnail.' . $src);
    $thumb_exists = ' &nbsp; | &nbsp; <a href="' . $thumb_folder_rel . 'thumbnail.' . rawurlencode($src) . '" rel="facybox_i" >' . i18n_r('CURRENT_THUMBNAIL') . '</a> <code>' . $thwidth . 'x' . $thheight . '</code>';
}
Ejemplo n.º 3
0
/**
 * generate a thumbnail
 * @param  str  $sub_path upload path
 * @param  str  $file     filename
 * @param  str  $out_file outfile name, can be null if show is true
 * @param  int  $w        desired width
 * @param  int  $h        desired max height, optional, will limit height and adjust width accordingly
 * @param  int  $quality  quality of image jpg and png
 * @param  bool $show     output to browser if true
 * @param  str $output_format optional output format, if not determining from out_file can be excusivly set (1|'GIF', 2|'JPG,'' 3|'PNG')
 * @param  boolean $upscale  true, allows image to scale up/zoom to fit thumbnail
 * @return bool            success
 */
function generate_thumbnail($file, $sub_path = '', $out_file = null, $w = null, $h = null, $crop = null, $quality = null, $show = false, $output_format = null, $upscale = false)
{
    //gd check, do nothing if no gd
    $php_modules = get_loaded_extensions();
    if (!in_arrayi('gd', $php_modules)) {
        return false;
    }
    $sub_path = tsl($sub_path);
    $upload_folder = GSDATAUPLOADPATH . $sub_path;
    $thumb_folder = GSTHUMBNAILPATH . $sub_path;
    $thumb_file = isset($out_file) && !empty($out_file) ? $thumb_folder . $out_file : '';
    create_dir($thumb_folder);
    require_once 'imagemanipulation.php';
    $objImage = new ImageManipulation($upload_folder . $file);
    if ($objImage->imageok) {
        if ($upscale) {
            $objImage->setUpscale();
        }
        // allow magnification
        if ($quality) {
            $objImage->setQuality($quality);
        }
        // set quality for jpg or png
        if (isset($output_format)) {
            $objImage->setOutputFormat($output_format);
        }
        // setoutput format, ignored if out_file specifies extension
        if (isset($w) && isset($h)) {
            $objImage->setImageWidth($w, $h);
        } elseif (isset($w)) {
            $objImage->setImageWidth($w);
            // if only specifiying width, scale to width only
            // $objImage->resize($w); // constrains both dimensions to $size, same as setImageWidth($w,$w);
        } elseif (isset($h)) {
            $objImage->setImageHeight($h);
            // if only specifiying width, scale to width only
        }
        if (isset($crop)) {
            $objImage->setAutoCrop($crop);
        }
        // die(print_r($objImage));
        $objImage->save($thumb_file, $show);
        return $objImage;
    } else {
        return false;
    }
}
Ejemplo n.º 4
0
//append the full path
$MovieFolder = $config['RootPath'] . '/uploads/media/movies/' . $MovieFolder;
//Create the movie directory
if (!mkdir($MovieFolder, 0755, true)) {
    $ERRORS->Add("The website was not able to create new directory for the movie.");
}
$ImageFolder = $MovieFolder . '/thumbnails';
//Create a folder for the images aswell
mkdir($ImageFolder, 0755, true);
//Let's start creating diferent size thumbs
$objImage = new ImageManipulation($tempFolder . '/' . $image);
//Verify the image
if ($objImage->imageok) {
    $objImage->setJpegQuality(100);
    //Start by making the default size image, no resize
    $objImage->save($ImageFolder . '/' . $image);
    //Index image 401x227
    $objImage->resize(401);
    $objImage->save($ImageFolder . '/index_' . $image);
    //Medium image 255x145
    $objImage->resize(255);
    $objImage->save($ImageFolder . '/medium_' . $image);
    //Small image 200x113
    $objImage->resize(200);
    $objImage->save($ImageFolder . '/small_' . $image);
    //delete the temp
    @unlink($tempFolder . '/' . $image);
} else {
    $ERRORS->Add("The uploaded thumbnail seems to be invalid.");
}
unset($objImage);
Ejemplo n.º 5
0
 function crop_picture_by_id()
 {
     @ob_clean();
     $user_id = CI::model('core')->userId();
     if (intval($user_id) == 0) {
         exit('Error! You are not logged in.');
     }
     $id = $_POST['id'];
     if ($id > 0) {
         $media = CI::model('core')->mediaGetById($id);
         if (!empty($media)) {
             require 'ImageManipulation.php';
             $file_path = MEDIAFILES . 'pictures/original/' . $media['filename'];
             $objImage = new ImageManipulation($file_path);
             if ($objImage->imageok) {
                 $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
                 //$objImage->resize(500);
                 //$objImage->show();
                 $objImage->save($file_path);
             } else {
                 echo 'Error!';
             }
         }
     }
     //	$src = 'flowers.jpg';
     //exit ();
     exit;
     //var_dump ( $_POST );
 }
Ejemplo n.º 6
0
 /**
  * @desc Generic functuion to upload media from the $_FILES array, also saves the data into the DB
  * @param $to_table
  * @param $to_table_id
  * @return $uploaded files array
  * @author		Peter Ivanov
  * @version 1.0
  * @since Version 1.0
  */
 function mediaUpload($to_table, $to_table_id, $queue_id = false, $resize_options = false)
 {
     $target_path = MEDIAFILES;
     $uploaded = array();
     if (empty($_FILES)) {
         return false;
     }
     $this->load->library('upload');
     if (!empty($_FILES)) {
         $params['session_id'] = $this->input->post("PHPSESSID");
         //load the session library the new way, by passing it the session id
         //
         $this->load->library('session', $params);
         $this->cleanCacheGroup('media/global');
         require_once APPPATH . 'libraries/' . 'ImageManipulation.php';
         foreach ($_FILES as $k => $item) {
             if (stristr($k, 'picture_') == true) {
                 $target_path = MEDIAFILES;
                 $filename = basename($_FILES[$k]['name']);
                 if (strval($filename) != '') {
                     $filename = strtolower($filename);
                     $path = $target_path . 'pictures/';
                     if (is_dir($path) == false) {
                         @mkdir($path);
                         //@chmod ( $path, '0777' );
                     }
                     $the_target_path = $target_path . 'pictures/original/';
                     $original_path = $the_target_path;
                     if (is_dir($the_target_path) == false) {
                         @mkdir($the_target_path);
                         //@chmod ( $the_target_path, '0777' );
                     }
                     $the_target_path = $the_target_path . $this->url_title($filename, $separator = 'dash', $no_slashes = false, $leave_dots = true);
                     if (is_file($the_target_path) == true) {
                         $filename = date("ymdHis") . basename($_FILES[$k]['name']);
                         $filename = $this->url_title($filename, $separator = 'dash', $no_slashes = false, $leave_dots = true);
                         $the_target_path = $original_path . $filename;
                     }
                     if (move_uploaded_file($_FILES[$k]['tmp_name'], $the_target_path)) {
                         if (is_file($the_target_path) == true) {
                             if (is_readable($the_target_path) == true) {
                                 if (!empty($resize_options)) {
                                     $objImage = false;
                                     $objImage = new ImageManipulation($the_target_path);
                                     if ($objImage->imageok) {
                                         $img_info = $objImage->image;
                                         $sizex = $img_info['sizex'];
                                         //var_dump($sizex);
                                         if (intval($resize_options['width']) < intval($sizex) and intval($resize_options['width']) > 1) {
                                             $objImage->resize(intval($resize_options['width']));
                                             $objImage->save($the_target_path);
                                         }
                                     }
                                 }
                                 $uploaded[$k] = $this->url_title($filename, $separator = 'dash', $no_slashes = false, $leave_dots = true);
                             }
                         }
                     }
                 }
                 if (empty($uploaded)) {
                     return false;
                 } else {
                     $sizes = array();
                     $sizes = $this->optionsGetByKeyAsArray('media_image_sizes');
                     foreach ($uploaded as $item) {
                         $extension = substr(strrchr($item, '.'), 1);
                         foreach ($sizes as $size) {
                             $image = $original_path . $item;
                             $newimage = $path . "{$size}/";
                             if (is_dir($newimage) == false) {
                                 @mkdir($newimage);
                             }
                             $newimage = $path . "{$size}/" . $item;
                             $image_quality = 80;
                             $max_height = $size;
                             $max_width = $size;
                             switch ($extension) {
                                 case 'jpg':
                                 case 'jpeg':
                                     $src_img = ImageCreateFromJpeg($image);
                                     $orig_x = ImageSX($src_img);
                                     $orig_y = ImageSY($src_img);
                                     $new_y = $max_height;
                                     $new_x = $orig_x / ($orig_y / $max_height);
                                     if ($new_x > $max_width) {
                                         $new_x = $max_width;
                                         $new_y = $orig_y / ($orig_x / $max_width);
                                     }
                                     $dst_img = ImageCreateTrueColor($new_x, $new_y);
                                     ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y);
                                     ImageJpeg($dst_img, $newimage, $image_quality);
                                     ImageDestroy($src_img);
                                     ImageDestroy($dst_img);
                                     break;
                                 case 'gif':
                                     $src_img = imagecreatefromgif($image);
                                     $orig_x = ImageSX($src_img);
                                     $orig_y = ImageSY($src_img);
                                     $new_y = $max_height;
                                     $new_x = $orig_x / ($orig_y / $max_height);
                                     if ($new_x > $max_width) {
                                         $new_x = $max_width;
                                         $new_y = $orig_y / ($orig_x / $max_width);
                                     }
                                     $dst_img = ImageCreateTrueColor($new_x, $new_y);
                                     ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y);
                                     imagegif($dst_img, $newimage, $image_quality);
                                     ImageDestroy($src_img);
                                     ImageDestroy($dst_img);
                                     break;
                                 case 'png':
                                     $src_img = imagecreatefrompng($image);
                                     $orig_x = ImageSX($src_img);
                                     $orig_y = ImageSY($src_img);
                                     $new_y = $max_height;
                                     $new_x = $orig_x / ($orig_y / $max_height);
                                     if ($new_x > $max_width) {
                                         $new_x = $max_width;
                                         $new_y = $orig_y / ($orig_x / $max_width);
                                     }
                                     $im_dest = imagecreatetruecolor($new_x, $new_y);
                                     imagealphablending($im_dest, false);
                                     imagecopyresampled($im_dest, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y);
                                     imagesavealpha($im_dest, true);
                                     imagepng($im_dest, $newimage);
                                     imagedestroy($im_dest);
                                     break;
                             }
                         }
                     }
                 }
             }
         }
         global $cms_db_tables;
         $table = $cms_db_tables['table_media'];
         $media_table = $table;
         foreach ($uploaded as $item) {
             if (strval($item) != '') {
                 $media_save = array();
                 $media_save['media_type'] = 'picture';
                 $media_save['filename'] = $item;
                 $media_save['to_table'] = $to_table;
                 $media_save['to_table_id'] = $to_table_id;
                 $new_media_id = $this->saveData($table, $media_save);
                 $media_save['id'] = $new_media_id;
             }
         }
         //
         if (trim($to_table) != '' and trim($to_table_id) != '') {
             $cache_group = "media/{$to_table}/{$to_table_id}";
             $this->cleanCacheGroup($cache_group);
         }
         $res = $media_save;
         $this->cleanCacheGroup('media/global');
         $this->mediaFixOrder($to_table, $to_table_id, 'picture');
         return $res;
     } else {
         return false;
     }
     //	exit ();
 }
Ejemplo n.º 7
0
 public function byURL($url)
 {
     if (!isset($url) || !is_string($url)) {
         trigger_error("Invalid input!", E_USER_ERROR);
     }
     // check if the image is downloadable
     $curlHandle = curl_init();
     curl_setopt_array($curlHandle, array(CURLOPT_URL => $url, CURLOPT_NOBODY => true, CURLOPT_HEADER => false));
     $res = curl_exec($curlHandle);
     if (!$res) {
         return "-11\nFile doesn't exist!";
     }
     $i = curl_getinfo($curlHandle);
     if ($i['download_content_length'] > MAX_FILE_SIZE) {
         return "-12\nFile too large!";
     }
     // Download the image!
     $this->file['tmp_name'] = tempnam("/tmp", "i2");
     $fileHandle = fopen($this->file['tmp_name'], 'w');
     $curlHandle = curl_init();
     curl_setopt_array($curlHandle, array(CURLOPT_URL => $url, CURLOPT_FILE => $fileHandle, CURLOPT_CONNECTTIMEOUT => DOWNLOAD_TIMEOUT, CURLOPT_BINARYTRANSFER => 1));
     $download = curl_exec($curlHandle);
     fclose($fileHandle);
     if (curl_errno($curlHandle) != 0) {
         return "-13\nInternal cURL error: (" . curl_errno($curlHandle) . ") " . curl_error($curlHandle);
     }
     $this->file['hash'] = hash_file("md5", $this->file['tmp_name']);
     // checks if image is new and if not only grants the image a new
     // timestamp
     $res = SQL::query("SELECT COUNT(*) as images FROM images" . " WHERE hash = '" . $this->file['hash'] . "' LIMIT 1");
     if ($res->fetch_object()->images > 0) {
         trigger_error("Hash is not unique, will only update image", E_USER_NOTICE);
         SQL::query("UPDATE images SET images.time = '" . time() . "' " . "WHERE hash = '" . $this->file['hash'] . "' LIMIT 1");
         return "2\nSuccess! Image updated in database!";
     } else {
         $this->file['name'] = split('/', $url);
         $this->file['name'] = $this->file['name'][count($this->file['name']) - 1];
         $this->cleanFilename();
         if (!copy($this->file['tmp_name'], I_IMAGE_DIR . DIRECTORY_SEPARATOR . $this->file['safeName'])) {
             return "-14\nCould not copy file to image directory";
         }
         $manip = new ImageManipulation($this->file['tmp_name']);
         $manip->thumbnail();
         $manip->save(I_THUMBNAIL_DIR . DIRECTORY_SEPARATOR . $this->file['safeName']);
         unset($manip);
         $this->insertIntoDB();
         return "1\nSuccess! '" . $this->file['safeName'] . "' uploaded!";
     }
 }
Ejemplo n.º 8
0
//Chmod the folder
//$CORE->ChmodWritable($file_path);
//$CORE->ChmodWritable($file_path . $thumb_folder);
//handle the upload
if (move_uploaded_file($tempFile, $file_src_new)) {
    //try deleting the temp file
    @unlink($tempFile);
} else {
    $ERRORS->Add("The website failed to upload your screenshot. If this problem presists please contact the administration.");
}
//resample the image
$objImage = new ImageManipulation($file_src_new);
if ($objImage->imageok) {
    //resample the image
    $objImage->setJpegQuality(100);
    $objImage->save($file_src_new);
    //make a thumb
    $objImage->resizeProper($thumb_width, $thumb_height);
    $objImage->save($file_src_new_thumb);
    //get the time
    $time = $CORE->getTime();
    $type = TYPE_SCREENSHOT;
    $status = SCREENSHOT_STATUS_PENDING;
    //insert into the database
    $insert = $DB->prepare("INSERT INTO `images` (`name`, `descr`, `added`, `account`, `image`, `type`, `status`) VALUES (:name, :descr, :added, :account, :image, :type, :status);");
    $insert->bindParam(':name', $title, PDO::PARAM_STR);
    $insert->bindParam(':descr', $descr, PDO::PARAM_STR);
    $insert->bindParam(':added', $time, PDO::PARAM_STR);
    $insert->bindParam(':account', $CURUSER->get('id'), PDO::PARAM_INT);
    $insert->bindParam(':image', $imageName, PDO::PARAM_STR);
    $insert->bindParam(':type', $type, PDO::PARAM_INT);
Ejemplo n.º 9
0
<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $src = 'google.png';
    require 'ImageManipulation.php';
    $objImage = new ImageManipulation($src);
    if ($objImage->imageok) {
        $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
        $objImage->resize(500);
        $objImage->show();
        // uncomment the following line to save the output image.
        $objImage->save('12345.png');
    } else {
        echo 'Error!';
    }
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>-->
    <!--<script src="jquery.Jcrop.pack.js" type="text/javascript"></script>-->
	
	<script src="./js/jquery.min.js" type="text/javascript"></script>
    <script src="./js/jquery.Jcrop.js" type="text/javascript"></script>
    <script src="./js/jquery.color.js" type="text/javascript"></script>
    <link rel="stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />
    <link rel="stylesheet" href="./css/jquery.Jcrop.extras.css" type="text/css" />
    <!--<link rel="stylesheet" href="demo_files/demos.css" type="text/css" />-->
	
        $w = ceil($dropHeight * $aspectratio);
        echo ($w . " " . $aspectratio);
        } */
 } else {
     if ($type == "CropImage") {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $src = $_POST['src'];
             require './javascripts/plugins/croping/ImageManipulation.php';
             $objImage = new ImageManipulation($src);
             if ($objImage->imageok) {
                 $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
                 $objImage->resize(500);
                 $filename_ext = pathinfo($src, PATHINFO_EXTENSION);
                 $src = preg_replace('/(\\.gif|\\.jpg|\\.png)/', '1', "{$src}");
                 $src = $src . "." . $filename_ext;
                 $objImage->save($src);
             } else {
                 echo 'Error!';
             }
             exit;
         }
     } else {
         if ($type == "getSideButtons") {
             session_start();
             $temp = $_SESSION['format'];
             $q = "Select * From shapes Where id='{$temp}'";
             $r = mysql_query($q);
             while ($row = mysql_fetch_array($r)) {
                 $formatName = $row['id'];
                 $front = $row['front'];
                 $back = $row['back'];
Ejemplo n.º 11
0
$_SESSION["state"]++;
$exp = '';
$ext = '.png';
if (isset($_POST['exp'])) {
    $exp = $_POST['exp'];
}
if ($exp == 'col') {
    $ext = '.jpg';
}
$user_folder = 'images/temp/';
require 'inc/imagemanipulation.php';
$objImage = new ImageManipulation('images/Mosaic' . $exp . $ext);
if ($objImage->imageok) {
    $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']);
    if ($exp == 'col') {
        $objImage->save($user_folder . $_SESSION["id"] . $_SESSION["state"] . $ext);
    } else {
        $objImage->save($user_folder . $_SESSION["id"] . '_' . $_SESSION["state"] . $ext);
    }
} else {
    echo 'Error!';
}
$_SESSION["currentS"] = $_SESSION["state"];
if ($exp != 'col') {
    if ($_SESSION["piping"] == 99) {
        $text = '
<div class="item">
	      <h2>Cropped Image</h2>
	      <img src="images/temp/' . $_SESSION["id"] . '_' . $_SESSION["state"] . $ext . '" alt="picture" width="281px" height="281px"/>
	      <dl class="details ui-helper-clearfix">
			<dt>