public function getFile($id, $size = false)
 {
     $file = $this->where(array('id' => (int) $id))->fetchOne();
     if (empty($file)) {
         return false;
     }
     $dir = UPLOAD_DIR . DS . 'attachment' . DS;
     $temp = TEMP_DIR . DS . 'attachment';
     File::mkdir($temp);
     if (!$size) {
         return $dir . $file['file'];
     }
     if ($size) {
         $tempfile = $temp . DS . $size . '-' . $file['file'];
         if (file_exists($tempfile)) {
             return $tempfile;
         }
         $resize = new Resize($dir . $file['file']);
         $sizes = getimagesize($dir . $file['file']);
         $index = 1;
         if ($sizes[0] >= $sizes[1]) {
             $index = $sizes[1] / $size;
         } else {
             $index = $sizes[0] / $size;
         }
         if ($index < 1) {
             $index = 1;
         }
         $resize->resizeImage(ceil($sizes[0] / $index), ceil($sizes[1] / $index));
         $resize->saveImage($tempfile);
         return $tempfile;
     }
 }
Ejemplo n.º 2
0
 function action()
 {
     $photo = array();
     $dir = $this->getDir("i/" . strtolower($_GET['classDiv']));
     $sort_id = 0;
     if ($_POST['parentID'] != 0 && ($row = DB::query_row("SELECT sort FROM `photo_tb` WHERE `parentID` = '" . DB::escape($_POST['parentID']) . "' && `table` = '" . DB::escape($_GET['classDiv']) . "' ORDER BY `sort` DESC"))) {
         $sort_id = $row['sort'];
     }
     foreach ($_FILES['img_arr']['tmp_name'] as $k => $v) {
         $sort_id++;
         DB::query("INSERT INTO `photo_tb` (`parentID`, `table`, `name`, `sort`) \n\t\t\tVALUES (\n\t\t\t\t'" . DB::escape($_POST['parentID']) . "',\n\t\t\t\t'" . DB::escape($_GET['classDiv']) . "',\n\t\t\t\t'" . DB::escape($_FILES['img_arr']['name'][$k]) . "',\n\t\t\t\t'" . $sort_id . "'\n\t\t\t)");
         $insert_id = DB::last_inserted_id();
         $_SESSION['photo'][$insert_id] = $insert_id;
         foreach (Config::$photo[$_GET['classDiv']] as $size) {
             $this->getDir($dir . "/" . self::getPathFile($insert_id));
             $e = explode('x', $size);
             if (count($e) == 1) {
                 Resize::resizeImage($e['0'], $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/" . $size) . "/" . $_FILES['img_arr']['name'][$k]);
             } else {
                 Resize::cropImage($e['0'], $e['1'], $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/" . $size) . "/" . $_FILES['img_arr']['name'][$k]);
             }
         }
         copy($v, $dir . "/" . self::getPathFile($insert_id) . "/" . $_FILES['img_arr']['name'][$k]);
         Resize::resizeImage(80, $v, $this->getDir($dir . "/" . self::getPathFile($insert_id) . "/thumb") . "/" . $_FILES['img_arr']['name'][$k]);
         $photo[] = array('src' => $dir . "/" . self::getPathFile($insert_id) . "/thumb/" . $_FILES['img_arr']['name'][$k], 'id' => $insert_id, 'sort' => $sort_id);
     }
     echo json_encode($photo);
     die;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments = array())
 {
     // Don't scale if we don't change the dimensions at all.
     if ($arguments['width'] !== $this->getToolkit()->getWidth() || $arguments['height'] !== $this->getToolkit()->getHeight()) {
         // Don't upscale if the option isn't enabled.
         if ($arguments['upscale'] || $arguments['width'] <= $this->getToolkit()->getWidth() && $arguments['height'] <= $this->getToolkit()->getHeight()) {
             return parent::execute($arguments);
         }
     }
     return TRUE;
 }
Ejemplo n.º 4
0
	public function testRectangle() {
		// Normal scaling with preserved aspect ratio.
		list($width, $height) = Resize::rectangle(560, 250, 480, 0);
		$this->assertEquals(215, $height);
		list($width, $height) = Resize::rectangle(256, 128, 0, 500);
		$this->assertEquals(1000, $width);
		
		// Enforce target dimensions (skewing the rectangle).
		$this->assertEquals(array(500, 400), Resize::rectangle(800, 600, 500, 400));
		
		// Test IF_*.
		list($width, $height) = Resize::rectangle(800, 600, 480, 0, Resize::IF_SMALLER);
		$this->assertEquals(600, $height);
		list($width, $height) = Resize::rectangle(480, 320, 800, 0, Resize::IF_BIGGER);
		$this->assertEquals(320, $height);
	}
Ejemplo n.º 5
0
 public function getCustomImageSizeResponse($id, $width, $height)
 {
     $repository = $this->manager->getRepository('EnhavoMediaBundle:File');
     $file = $repository->find($id);
     if ($file === null) {
         throw new NotFoundResourceException();
     }
     if ($width && !$height) {
         $path = $this->path . '/custom/' . $width;
         $this->createPathIfNotExists($path);
         $filepath = $path . '/' . $id;
         if (!file_exists($filepath) || filemtime($filepath) < filemtime($this->getFilepath($file))) {
             Resize::make($this->getFilepath($file), $filepath, $width, 99999);
         }
     } else {
         $path = $this->path . '/custom/' . $width . 'x' . $height;
         $this->createPathIfNotExists($path);
         $filepath = $path . '/' . $id;
         if (!file_exists($filepath) || filemtime($filepath) < filemtime($this->getFilepath($file))) {
             Thumbnail::make($this->getFilepath($file), $filepath, $width, $height);
         }
     }
     $response = new BinaryFileResponse($filepath);
     $response->headers->set('Content-Type', $file->getMimeType());
     return $response;
 }
Ejemplo n.º 6
0
<?php

set_time_limit(10000);
error_reporting(E_ALL ^ E_NOTICE);
include '../../vendor/booty/lib/Resize.class.php';
// Folder where the (original) images are located with trailing slash at the end
$images_dir = '../../';
// Image to resize
$image = $_GET['t'];
$imgpath = $images_dir . $image;
/* Some validation */
if (!@file_exists($imgpath)) {
    exit('The requested image does not exist.');
}
$info = @GetImageSize($imgpath);
$mimetype = $info['mime'];
header("Content-Type: " . $mimetype);
// Get the new with & height
$new_width = (int) $_GET['w'];
$new_height = (int) $_GET['h'];
$im = new Resize($imgpath);
if ($mimetype == 'image/png') {
    imagepng($im->crop($new_width, $new_height, "hola"));
} else {
    imagejpeg($im->crop($new_width, $new_height, "hola"));
}
 function getImageSize($id, $user_id, $size)
 {
     $photo = $this->getPhotoByID($id);
     $file = $photo;
     if (empty($file)) {
         return false;
     }
     $dir = ConnectionHelper::getPhotoDir($user_id) . 'original/';
     $temp = TEMP_DIR . DS . 'avatars';
     File::mkdir($temp);
     if (!$size) {
         return $dir . $file['file'];
     }
     if ($size) {
         $tempfile = $temp . DS . 'user-' . $user_id . '-' . $id . '-' . $size . '-' . $file['file'];
         if (file_exists($tempfile)) {
             return $tempfile;
         }
         $resize = new Resize($dir . $file['file']);
         $sizes = getimagesize($dir . $file['file']);
         $index = 1;
         if ($sizes[0] >= $sizes[1]) {
             $index = $sizes[1] / $size;
         } else {
             $index = $sizes[0] / $size;
         }
         if ($index < 1) {
             $index = 1;
         }
         $resize->resizeImage(ceil($sizes[0] / $index), ceil($sizes[1] / $index));
         $resize->saveImage($tempfile);
         return $tempfile;
     }
 }
 private function outputImage($query)
 {
     extract(Options::getOptions());
     $queryParam = sprintf('%s-query', $baseUrl);
     $pathParam = sprintf('%s-path', $baseUrl);
     if (empty($query->query[$queryParam]) || empty($query->query[$pathParam])) {
         return;
     }
     $params = $query->query[$queryParam];
     $path = preg_replace('/\\.\\.\\//', '', $query->query[$pathParam]);
     $params = explode('-', $params);
     $parsed = array();
     foreach ($params as $param) {
         if (preg_match("/(?P<operation>[a-z]{1})(?P<value>[\\S]*)/", $param, $matches) && isset(static::$operations[$matches['operation']])) {
             $parsed[static::$operations[$matches['operation']]] = $matches['value'];
         }
     }
     foreach ($parsed as $key => $value) {
         switch ($key) {
             case 'crop':
                 $dimensions = explode('x', $value);
                 $parsed['width'] = intval($dimensions[0]);
                 $parsed['height'] = intval($dimensions[1]);
                 $parsed['cropped'] = true;
                 unset($parsed[$key]);
                 break;
             case 'extension':
                 $path .= '.' . preg_replace('/[^0-9a-zA-Z]*/', '', $value);
                 unset($parsed[$key]);
                 break;
             case 'offset':
                 $dimensions = explode('x', $value);
                 $parsed['offsetX'] = intval($dimensions[0]);
                 $parsed['offsetY'] = intval($dimensions[1]);
                 unset($parsed[$key]);
                 break;
             case 'width':
             case 'height':
                 $parsed[$key] = intval($value);
                 break;
         }
     }
     $image = Resize::getImage($path, $parsed);
     if (is_wp_error($image)) {
         wp_die($image);
     }
     // Set caching headers, and stream
     header('Pragma: public');
     header('Cache-Control: max-age=86400');
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
     $image->stream();
     exit;
 }
Ejemplo n.º 9
0
 /**
  *
  * @param array $imgData
  * @return $this
  */
 public function save($imgData)
 {
     if (empty($this->uid)) {
         $this->uid = md5(microtime(true) . uniqid(md5(serialize($imgData)) . rand(0, 1000)));
     }
     if (!empty($this->name)) {
         $this->delete();
     }
     $this->loadImageData($imgData);
     $this->createImageDir();
     foreach ($this->types as $type => $sizes) {
         $this->currentType = $type;
         $fileName = $this->getPath();
         $imageObject = Resize::resize($imgData['tmp_name'], $fileName, $sizes['w'], $sizes['h']);
         $this->sizes[$type] = $imageObject->getResizedInfo();
     }
     $this->currentType = self::DEFAULT_TYPE;
     return $this;
 }
Ejemplo n.º 10
0
function imageResize($file, $newWidth, $newHeight, $savePath, $option = null, $quality = null)
{
    $r = new Resize($file);
    $r->resizeImage($newWidth, $newHeight, $option);
    $r->saveImage($savePath, $quality);
}
Ejemplo n.º 11
0
// Edit upload location here
$destination_path = base64_decode($_POST['path_2_upload']);
$link_2_upload = base64_decode($_POST['link_2_upload']);
$fileName = basename($_FILES['myfile']['name']);
@mkdir($destination_path, 0777, true);
$result = 0;
$target_path = $destination_path . $fileName;
$markedImageName = 'marked_' . $fileName;
$extensions = array('.png', '.gif', '.jpg', '.jpeg', '.bmp', '.PNG', '.GIF', '.JPG', '.JPEG', '.BMP');
$extension = strrchr($_FILES['myfile']['name'], '.');
if (in_array($extension, $extensions)) {
    if (move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
        include_once 'resize.class.php';
        try {
            $obj = new Resize($target_path);
            $obj->setNewImage($destination_path . $markedImageName);
            // 			$obj->setWaterMarkImage("watermark.png");
            // 			$obj->setWaterMarkOpacity(40);
            // 			$obj->setWaterMarkPosition('bottomLeft');
            $obj->setProportionalFlag('V');
            $obj->setProportional(1);
            // 			$obj->setDegrees(90);
            $obj->setNewSize(60000, 60000);
            $obj->make();
        } catch (Exception $e) {
            die($e);
        }
        $result = 1;
    }
}
Ejemplo n.º 12
0
 function load_foto_adv($file, $img_old, $img_small_old, $x, $y)
 {
     global $user;
     require_once 'classes/thumblib.inc.php';
     require_once 'classes/resize.class.php';
     $size = new Resize();
     $folder = 'adv/';
     @mkdir($folder, 0777);
     $size->dir = $folder;
     // Директория изображений
     $size->original = true;
     if ($file['name']) {
         $size->setResize($file);
         if (!$size->error) {
             @unlink($img_old);
             @unlink($img_small_old);
             $img_small = $size->small;
             $img = $size->image;
             $thumb = PhpThumbFactory::create($img);
             $thumb->resize($x, 0);
             $thumb->save($img_small);
             $img = $img;
             $img_small = $img_small;
         } else {
             $error = $size->error;
         }
     } else {
         $img_small = $img_small_old;
         $img = $img_old;
     }
     $result = array('error' => $error, 'img' => $img, 'img_small' => $img_small);
     return $result;
 }
Ejemplo n.º 13
0
<?php

require 'class.resize.php';
$resize = new Resize();
if (array_key_exists('debug', $_GET)) {
    $resize->debug();
} else {
    $resize->output();
}
Ejemplo n.º 14
0
	/**
	 * Resize an embed tag by matching all width/height
	 * attributes in the given $markup, using the first pair
	 * to calculate new width/height values and then replacing
	 * the old attributes. This method is quite dumb and will
	 * not handle unexpected or complicated markup well.
	 * 
	 * @param string $markup
	 * @param integer $width
	 * @param integer $height
	 * @param integer $when
	 * 
	 * @return string
	 */
	public static function using_attributes($markup, $width, $height,
			$when = Resize::ALWAYS) {
		// These two variable names must match the two keys in the
		// $search array below.
		$attrWidth = 0;
		$attrHeight = 0;
		
		// Regexes to match width and height attributes in markup.
		$search = array(
			'attrWidth' => '/width(\s*)=\1"?\d+"?/i',
			'attrHeight' => '/height(\s*)=\1"?\d+"?/i'
		);
		
		$matches = array();
		
		// Find all width and height attributes in the markup given.
		foreach ($search as $key => $pattern) {
			if (preg_match($pattern, $markup, $matches))
				if (preg_match('/\d+/i', $matches[0], $matches))
					$$key = $matches[0];
		}
		list($width, $height) = Resize::rectangle($attrWidth, $attrHeight, $width, $height, $when);
		$replace = array(
			"width=\"{$width}\"",
			"height=\"{$height}\""
		);
		
		$markup = strip_tags($markup, '<iframe><object><param><embed><video>');
		$markup = preg_replace($search, $replace, $markup);
		
		return $markup;
	}
Ejemplo n.º 15
0
<?php

require '../library/RM/Photo/Resize.php';
try {
    $resize = new Resize(dirname(__FILE__), $_GET['image']);
    $resize->resize(isset($_GET['width']) ? $_GET['width'] : null, isset($_GET['height']) ? $_GET['height'] : null, isset($_GET['crop']));
    $resize->echoImage();
} catch (Exception $e) {
    header('Content-Type: image/png');
    $image = imagecreatetruecolor(1, 1);
    imagesavealpha($image, true);
    $color = imagecolorallocatealpha($image, 0x0, 0x0, 0x0, 127);
    imagefill($image, 0, 0, $color);
    echo imagepng($image);
    imagedestroy($image);
}
Ejemplo n.º 16
0
 public static function uploadImage($file_path = '', $file = '', $prefix = 'file', $uploadInfo = array(), $type = 'normal')
 {
     $path_orig = $file_path;
     if ($file['name'] != '') {
         $file_name_orig = $file['name'];
         $file_name = self::fileNameNew($file, $prefix);
         if (!is_dir($path_orig)) {
             mkdir($path_orig, 0777, true);
         }
         if (move_uploaded_file($file['tmp_name'], $path_orig . $file_name)) {
             switch ($type) {
                 case 'square':
                     foreach ($uploadInfo as $key => $value) {
                         $directory = $file_path . $key;
                         if (!is_dir($directory)) {
                             mkdir($directory, 0777, true);
                         }
                         self::thumbSquare($path_orig . $file_name_orig, $directory . $file_name, 100, $value['width'], $value['height']);
                     }
                     break;
                 case 'normal':
                     foreach ($uploadInfo as $key => $value) {
                         $directory = $file_path . $key;
                         if (!is_dir($directory)) {
                             mkdir($directory, 0777, true);
                         }
                         //                            echo $value['height'];
                         //                            echo $value['width'];
                         //                            exit;
                         if ($value['width'] == 70 || $value['width'] == 270 || $value['width'] == 500) {
                             $option = 'crop';
                             $Resizer = new Resize($path_orig . $file_name);
                             $Resizer->resizeImage($value['width'], $value['height'], $option);
                             $Resizer->saveImage($directory . $file_name, 100);
                         } else {
                             self::thumbNormal($path_orig . $file_name, $directory . $file_name, 100, $value['width'], $value['height']);
                         }
                     }
                     break;
                 case 'auto':
                     foreach ($uploadInfo as $key => $value) {
                         $directory = $file_path . $key;
                         if (!is_dir($directory)) {
                             mkdir($directory, 0777, true);
                         }
                         $option = 'auto';
                         $Resizer = new Resize($path_orig . $file_name);
                         $Resizer->resizeImage($value['width'], $value['height'], $option);
                         $Resizer->saveImage($directory . $file_name, 100);
                     }
                     break;
                 case 'crop':
                     foreach ($uploadInfo as $key => $value) {
                         $directory = $file_path . $key;
                         if (!is_dir($directory)) {
                             mkdir($directory, 0777, true);
                         }
                         $option = 'crop';
                         $Resizer = new Resize($path_orig . $file_name);
                         $Resizer->resizeImage($value['width'], $value['height'], $option);
                         $Resizer->saveImage($directory . $file_name, 100);
                     }
                     break;
                 default:
             }
             //				die('file uploaded');
             return $file_name;
         } else {
             die('file NOT uploaded');
             return false;
         }
     }
 }
Ejemplo n.º 17
0
$destination_path = base64_decode($_POST['path_2_upload']);
$link_2_upload = base64_decode($_POST['link_2_upload']);
$max_upload_size = explode('x', $_POST['max_upload_size']);
$markedImage = '';
$fileName = basename($_FILES['myfile']['name']);
@mkdir($destination_path, 0777, true);
$result = 0;
$target_path = $destination_path . $fileName;
$markedImageName = time() . '-' . $fileName;
$extensions = array('.png', '.gif', '.jpg', '.jpeg', '.bmp', '.PNG', '.GIF', '.JPG', '.JPEG', '.BMP');
$extension = strrchr($_FILES['myfile']['name'], '.');
if (in_array($extension, $extensions)) {
    if (move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
        include_once '../resize.class.php';
        try {
            $obj = new Resize($target_path);
            $obj->setNewImage($destination_path . $markedImageName);
            //			$obj->setWaterMarkImage($path_2_watermark);
            //			$obj->setWaterMarkOpacity(100);
            //			$obj->setWaterMarkPosition('bottomLeft');
            $obj->setProportionalFlag('V');
            $obj->setProportional(1);
            // 			$obj->setDegrees(90);
            $obj->setNewSize($max_upload_size[1], $max_upload_size[0]);
            $obj->make();
        } catch (Exception $e) {
            die($e);
        }
        $result = 1;
    }
}
Ejemplo n.º 18
0
 function _resize(&$model, $field, $path, $style, $geometry)
 {
     $filename = $model->data[$model->alias][$field];
     $srcFile = $path . $filename;
     $destFile = $path . $style . '_' . $filename;
     if ($this->_isSuffixStyle($model, $field)) {
         $pathInfo = $this->_pathinfo($path . $filename);
         $destFile = $path . $pathInfo['filename'] . '_' . $style . '.' . $pathInfo['extension'];
     }
     $options = $this->settings[$model->alias][$field];
     $method = $options['thumbnailMethod'];
     App::import('Lib', 'Upload.Resize');
     $Resize = new Resize($method, $srcFile);
     return $Resize->process($destFile, $geometry, $options['thumbnailQuality']);
 }
Ejemplo n.º 19
0
 function addCategoryImg($id)
 {
     if (isset($_FILES['image']['name']) && $_FILES['image']['name']) {
         $name = $_FILES['image']['name'];
         $arr = explode('.', $name);
         $ext = end($arr);
         $rand = rand(1000000, 9999999);
         $filename = $rand . '.' . $ext;
         $path = APP . 'webroot/profile/' . $filename;
         move_uploaded_file($_FILES['image']['tmp_name'], $path);
         $resizeObj = new Resize($path);
         $resizeObj->resizeImage(250, 180, 'exact');
         $resizeObj->saveImage(APP . 'webroot/profile_resize/' . $filename, 100);
         //echo $path;die();
         unset($resizeObj);
         $resizeObj = new Resize($path);
         $resizeObj->resizeImage(600, 432, 'exact');
         $resizeObj->saveImage('profile_resize1/' . $filename, 100);
         unlink($path);
     }
     $this->loadModel('Galleryimgs');
     $arr['img'] = $filename;
     $arr['title'] = $_POST['category-img-title'];
     $arr['cat_id'] = $id;
     $this->Galleryimgs->create();
     $this->Galleryimgs->save($arr);
     $this->redirect('/dashboard/gallery');
 }