Example #1
0
 function getImage($hash, $size = false)
 {
     $path = ROOT . DS . 'upload' . DS . $hash . DS;
     $fullpath = ROOT . DS . 'upload' . DS . $hash . DS . $hash;
     $pm = new PictshareModel();
     $type = $pm->isTypeAllowed($pm->getTypeOfFile($fullpath));
     if (!$type) {
         return false;
     }
     if (is_array($size)) {
         $width = $size[0];
         $height = $size[1];
     } else {
         if ($size) {
             $width = $size;
             $height = $size;
         }
     }
     if ($width && $height && $type != 'gif') {
         $filename = $width . 'x' . $height . '_' . $hash;
     } else {
         $filename = $hash;
     }
     if (file_exists($path . $filename)) {
         return '/' . $filename;
     }
     $thumb = new easyphpthumbnail();
     if ($width == $height) {
         $thumb->Thumbsize = $width;
     } else {
         $size = getimagesize($fullpath);
         if ($width / $height == $size[0] / $size[1]) {
             $thumb->Thumbwidth = $width;
             $thumb->Thumbheight = $height;
         } else {
             if ($width > $height) {
                 $thumb->Thumbsize = $height;
             } else {
                 $thumb->Thumbsize = $width;
             }
         }
         //$thumb -> Thumbwidth = $width;
         //$thumb -> Thumbheight = $height;
     }
     $thumb->Inflate = false;
     $thumb->Thumblocation = $path;
     //$thumb -> Thumbsaveas = $type;
     $thumb->Thumbfilename = $filename;
     $thumb->Createthumb($fullpath, 'file');
     //var_dump($thumb -> Thumblocation.$thumb -> Thumbfilename);
     return '/' . $filename;
 }
Example #2
0
 /**
  * Метод для генерации изображения
  * @param string $url    УРЛ изображения
  * @param string $file_output    Название изображения для сохранения
  * @param int $w_o, $h_o    Максимальные ширина и высота генерируемого изображения
  * @return string    Результат выполнения false - изображения нет, up - успешно записали и нужно обновиться, ok - изображение существует и не требует модификации
  */
 private function resize($file_input, $file_output, $w_o, $h_o, $percent = false)
 {
     //Если источник не указан
     if (!$file_input) {
         return false;
     }
     $time = time();
     //папка для работы с изображением и качество сжатия
     $rootfolder = $this->params->get('rootfolder', 'images/avatar');
     $imgcr = $this->params->get('imgcr', 80);
     //если папка для складирования аватаров не существует создаем ее
     if (!JFolder::exists(JPATH_BASE . '/' . $rootfolder)) {
         JFolder::create(JPATH_BASE . '/' . $rootfolder);
         file_put_contents(JPATH_BASE . '/' . $rootfolder . '/index.html', '');
     }
     // Генерируем имя tmp-изображения
     $tmp_name = JPATH_BASE . '/tmp/' . $file_output;
     $output_path = JPATH_BASE . '/' . $rootfolder . '/';
     $output_name = $output_path . $file_output;
     //Если файл существует и время замены не подошло возвращаем статус 'ok'
     if (is_file($output_name)) {
         if (filemtime($output_name) > $time - $this->params->get('updatetime', 86400)) {
             return 'ok';
         }
     }
     //заузка файла
     $uploaded = $this->upload($file_input, $tmp_name);
     if ($uploaded) {
         $thumb = new easyphpthumbnail();
         $thumb->Chmodlevel = '0644';
         $thumb->Quality = $imgcr;
         $thumb->Thumbheight = $h_o;
         $thumb->Thumbwidth = $w_o;
         $thumb->Thumblocation = $output_path;
         $thumb->Createthumb($tmp_name, 'file');
         unlink($tmp_name);
         if (is_file($output_name)) {
             return 'up';
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #3
0
// medidas para um tamanho em escala (mantem a proporção)
$sWidth = (int) $_GET['maxw'];
$sHeight = (int) $_GET['maxh'];
// medidas para um tamanho exato
// ajusta e, se necessário, corta a imagem para conseguir o tamanho sem distorcer...
$eWidth = (int) $_GET["w"];
$eHeight = (int) $_GET["h"];
if ($sWidth && $sHeight) {
    $sType = 'scale';
}
if ($eWidth && $eHeight) {
    $sType = 'exact';
}
include_once 'easyphpthumbnail.class.php';
// thumbnail
$thumb = new easyphpthumbnail();
if (file_exists($image)) {
    if ($thumb) {
        // largura e altura da imagem original
        $sz = getimagesize($image);
        $origW = $sz[0];
        $origH = $sz[1];
        // indica a largura como medida principal
        $setW = false;
        if ($sType == 'scale') {
            $width = $sWidth;
            $height = $sHeight;
            // se 'A' < 'B' seta a largura
            if ($width / $origW < $height / $origH) {
                $thumb->Thumbwidth = $width;
            } else {
Example #4
0
 /**
  * save or update product
  * @return void 
  */
 function save()
 {
     $db =& JFactory::getDBO();
     $row = JTable::getInstance('product', 'Table');
     $post = JRequest::get('post');
     if (!$row->bind(JRequest::get('post'))) {
         echo $row->getError();
         exit;
     }
     $row->name = trim($row->name);
     $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->shortdesc = trim(JRequest::getVar('shortdesc', '', 'post', 'string', JREQUEST_ALLOWRAW));
     $row->mediumimage = trim(JRequest::getVar('mediumimage', '', 'post', 'string', JREQUEST_ALLOWRAW));
     $row->intro = trim(JRequest::getVar('intro', '', 'post', 'string', JREQUEST_ALLOWRAW));
     $row->image = empty($row->image) && isset($post['images']) ? $post['images'][0] : $row->image;
     if (empty($row->date)) {
         $row->date = date('Y-m-d');
     }
     $row->currency = 'VNĐ';
     // upload image
     $thumbnail = JRequest::getVar('thumbnail', null, 'files', 'array');
     $row->thumbnail = JRequest::getVar('old_thumbnail');
     if (!empty($thumbnail['tmp_name'])) {
         if (!empty($row->thumbnail)) {
             @unlink($this->_path . $row->thumbnail);
         }
         $row->thumbnail = uploadImage($thumbnail, $this->_path);
     }
     for ($i = 1; $i < 1; $i++) {
         ${largeimage . $i} = JRequest::getVar('largeimage' . $i, null, 'files', 'array');
         $row->{largeimage . $i} = JRequest::getVar('old_largeimage' . $i);
         if (!empty(${largeimage . $i}['tmp_name'])) {
             if (!empty($row->{largeimage . $i})) {
                 @unlink($this->_path . $row->{largeimage . $i});
                 @unlink($this->_path . 'thumbnail/' . $row->{largeimage . $i});
             }
             $row->{largeimage . $i} = uploadImage(${largeimage . $i}, $this->_path);
             // create thumbnail
             $thumb = new easyphpthumbnail();
             $thumb->Thumbheight = 60;
             // Create the thumbnail and output to file
             $thumb->Thumblocation = $this->_path . 'thumbnail/';
             $thumb->Thumbprefix = '';
             $thumb->Createthumb($this->_path . $row->{largeimage . $i}, 'file');
         }
     }
     if ($row->store()) {
         // save upload img
         if (isset($post['images'])) {
             foreach ($post['images'] as $fid) {
                 $row_img = JTable::getInstance('images', 'Table');
                 $row_img->id = $fid;
                 $row_img->proid = $row->id;
                 if (!$row_img->store()) {
                     echo $row->getError();
                     exit;
                 }
             }
         }
         $this->updateCode($row->id);
         return $row->id;
     } else {
         echo $row->getError();
     }
 }
Example #5
0
<?php

define('_JEXEC', 1);
define('JPATH_BASE', '../../../../');
define('JPATH_HERE', '');
define('DS', DIRECTORY_SEPARATOR);
require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require_once JPATH_BASE . DS . 'includes' . DS . 'framework.php';
require_once 'easyphpthumbnail.class.php';
$mainframe =& JFactory::getApplication('site');
$uploaddir = JPATH_BASE . 'images/products/';
$thumbdir = JPATH_BASE . 'images/products/thumbs/';
$params =& JComponentHelper::getParams('com_products');
$thumb = new easyphpthumbnail();
$thumb->Thumbheight = $params->get('thump_height', '90');
$thumb->Thumbwidth = $params->get('thump_width', '90');
// Create the thumbnail and output to file
$thumb->Thumblocation = $thumbdir;
$thumb->Thumbprefix = '';
$xtimex = JRequest::getVar('xtimex', '');
$newname = $xtimex . $_FILES['uploadfile']['name'];
$file = $uploaddir . basename($newname);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
    echo "success";
    @$thumb->Createthumb($file, 'file');
} else {
    echo "error";
}
Example #6
0
 private function createThumb($file)
 {
     if (!file_exists($this->pasta_thumb)) {
         mkdir($this->pasta_thumb, 0777);
     }
     $thumb = new easyphpthumbnail();
     $thumb->Thumbheight = 100;
     $thumb->Thumblocation = $this->pasta_thumb;
     $thumb->Createthumb($file, "file");
 }
        $thumb->Thumbheight = $_POST['height'];
        /****** $thumb -> Quality = 100;  if quality increased , the size of img will multiply many times *****/
        $thumb->Inflate = true;
        $thumb->Createthumb($src_image_fn, 'file');
        $thumb = dirname(__FILE__) . "/" . $_POST['src_image'];
        if (copy($thumb, dirname(__FILE__) . "/users/thumb/" . $_POST['src_image'])) {
            unlink($thumb);
            $status_check = true;
        }
    }
}
//  method (1)
//  After resize the image .. next step is crop it ..
if ($status_check == true) {
    $src_image_thumb = dirname(__FILE__) . "/users/thumb/" . $_POST['src_image'];
    $thumb = new easyphpthumbnail();
    $thumb->Thumbwidth = 300;
    $thumb->Thumbheight = 300;
    /****** $thumb -> Quality = 90;   if quality increased , the size of img multiply many times ******/
    $thumb->Cropimage = array(1, 1, $_POST['left'], $_POST['right'], $_POST['top'], $_POST['bottom']);
    $thumb->Createthumb($src_image_thumb, 'file');
    $thumb = dirname(__FILE__) . "/" . $_POST['src_image'];
    unlink(dirname(__FILE__) . "/users/thumb/" . $_POST['src_image']);
    if (copy($thumb, $src_image_thumb)) {
        unlink($thumb);
        $status_check = false;
        $array_msg = array("success" => "crop image successful", "src_img" => "../users/thumb/" . $_POST['src_image']);
        echo json_encode($array_msg);
    }
}
/*
Example #8
0
	/**
	 *
	 * 미디어 썸네일 생성 및 패스 리턴
	 *
	 * @param string $ns 미디어 폴더 경로
	 * @param string $filename 미디어 파일명
	 * @param int $thumb_width 생성할 썸네일 너비
	 * @param int $thumb_height 생성할 썸네일 높이
	 * @param int $quality 썸네일 품질
	 * @return string 썸네일 경로
	 */
	function getMediaThumb($ns, $filename, $thumb_width, $thumb_height, $quality=90, $crop = false) {
			
		$bo_table = $this->wiki['bo_table'];
		$write_table = $this->g4['write_prefix'] . $bo_table;

		// 파일 정보 로드
		$media =& wiki_class_load("Media");
		$fileinfo = $media->getFile($ns, $filename);
		if(!$fileinfo) {
			return;
		}
			
		// 원본 이미지 파일 경로
		$file = $fileinfo['path'];
		if(!file_exists($file)) return "";
		$pathinfo = pathinfo($file);
		$extension = strtolower($pathinfo['extension']);

		// 확장자 검사 : 가능 이미지 아니면 원본 이미지 경로 반환
		if ($extension != 'jpg' && $extension != 'jpeg' && $extension != 'png' && $extension != 'gif') {
			return $this->wiki['url'] . "/data/".$this->bo_table."/files/".$fileinfo['source'];
		}

		// 원본 이미지 파일명
		$filename = $fileinfo['source'];
			
		// 썸네일 파일 패스  (썸네일 파일 명 : 게시판아이디-파일인덱스-퀄리티)
		$croping = ($crop ? "-c" : "");
		$thumb_name = "media-".$bo_table."-".$fileinfo['id'] . "-". $quality . $croping . "_".$thumb_width."x".$thumb_height. "." . $extension;
		$thumb_file = $this->thumb_path."/".$thumb_name;
		
		// 썸네일이 이미 존재하면 리턴
		if(file_exists($thumb_file)) return $this->thumb_url . "/". $thumb_name;
			
			
		if($crop) {						
			$sizes = getimagesize($file);			
	    $source_width = $sizes[0];
	    $source_height = $sizes[1];					
			$top = $left = $right = $bottom = 0;				
			
			// 원본 가로가 길 경우
	    if (($source_width / $source_height) > ($thumb_width / $thumb_height)) {
	        $temp_width = $source_height * $thumb_width / $thumb_height;
	        $right = $left = ($source_width - $temp_width) / 2;
	    }			
			// 원본 세로가 길 경우
	    if (($source_width / $source_height) < ($thumb_width / $thumb_height)) {
	        $temp_height = $source_width * $thumb_height / $thumb_width;
	        $top = $bottom = ($source_height - $temp_height) / 2;
	    }
		}

		$thumbLib = new easyphpthumbnail;
		$thumbLib->Thumbwidth = $thumb_width;
		$thumbLib->Thumbheight = $thumb_height;
		$thumbLib->Quality = $quality;
		$thumbLib->Thumblocation = $this->thumb_path."/";
		$thumbLib->Thumbfilename = $thumb_name;
		if($crop) {
			$thumbLib->Cropimage = array(1, 1, $left, $right, $top, $bottom);
		}

		$thumbLib->Createthumb($file, 'file');
			
		return $this->thumb_url . "/".$thumb_name;
	}