Exemple #1
0
        $file_name = $file_name . '.jpg';
        break;
}
//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);
Exemple #2
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 ();
 }
Exemple #3
0
//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);
$ERRORS->Check('/index.php?page=movie-add');
//Check if we have more then one movie
<?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" />-->