/**
  * Widgets run function
  * @param integer $id
  * @param string $attribute
  * @throws CHttpException
  */
 public function run()
 {
     if (Yii::app()->getRequest()->isPostRequest) {
         if (!file_exists($this->uploadPath)) {
             throw new CHttpException(Yii::t('zii', 'Invalid upload path'));
         }
         $uploader = new qqFileUploader($this->allowedExtensions, $this->sizeLimit);
         $result = $uploader->handleUpload($this->uploadPath, true, session_id());
         $gd = new GdImage();
         // step 1: make a copy of the original
         $filePath = $this->uploadPath . '/' . $result['filename'];
         $copyName = $gd->createName($result['filename'], '_FULLSIZE');
         $gd->copy($filePath, $this->uploadPath . '/' . $copyName);
         // step 2: Scale down or up this image so it fits in the browser nicely, lets say 500px is safe
         $oldSize = $gd->getProperties($filePath);
         if ($oldSize['w'] >= $this->resizeWidth) {
             $newSize = $gd->getAspectRatio($oldSize['w'], $oldSize['h'], $this->resizeWidth, 0);
             $gd->resize($filePath, $newSize['w'], $newSize['h']);
         }
         echo json_encode($result);
         Yii::app()->end();
     } else {
         throw new CHttpException(Yii::t('zii', 'Invalid request'));
     }
 }
 /**
  * Widgets run function
  * @throws CHttpException
  */
 public function run()
 {
     if (Yii::app()->getRequest()->isPostRequest) {
         if (!file_exists($this->uploadPath)) {
             throw new CHttpException(Yii::t('zii', 'Invalid upload path'));
         }
         $gd = new GdImage();
         foreach ($_POST['imgcrop'] as $k => $v) {
             // 1) delete resized, move to full size
             $filePath = $this->uploadPath . '/' . $v['filename'];
             $fullSizeFilePath = $this->uploadPath . '/' . $gd->createName($v['filename'], '_FULLSIZE');
             unlink($filePath);
             rename($fullSizeFilePath, $filePath);
             // 2) compute the new coordinates
             $scaledSize = $gd->getProperties($filePath);
             if ($scaledSize['w'] >= $this->resizeWidth) {
                 $percentChange = $scaledSize['w'] / $this->resizeWidth;
                 // we know we scaled by width of px in upload
             } else {
                 $percentChange = 1;
             }
             $newCoords = array('x' => $v['x'] * $percentChange, 'y' => $v['y'] * $percentChange, 'w' => $v['w'] * $percentChange, 'h' => $v['h'] * $percentChange);
             // 3) crop the full size image
             $gd->crop($filePath, $newCoords['x'], $newCoords['y'], $newCoords['w'], $newCoords['h']);
             // 4) resize the cropped image to whatever size we need (lets go with 200 wide)
             $ar = $gd->getAspectRatio($newCoords['w'], $newCoords['h'], $this->cropWidth, 0);
             $gd->resize($filePath, $ar['w'], $ar['h']);
         }
         echo '1';
         Yii::app()->end();
     } else {
         throw new CHttpException(Yii::t('zii', 'Invalid request'));
     }
 }
示例#3
0
ini_set('log_errors', 1);
error_reporting(E_ALL);
define('DS', DIRECTORY_SEPARATOR);
define('CURR_DIR', dirname(__FILE__) . DS);
define('UPLOAD_DIR', CURR_DIR . "uploads" . DS);
require "gd_image.php";
$gd = new GdImage();
foreach ($_POST['imgcrop'] as $k => $v) {
    /*
    	1) delete the resized image from upload, we will only be working with the full size
    	2) compute new coordinates of full size image
    	3) crop full size image
    	4) resize the cropped image to what ever size we need
    */
    // 1) delete resized, move to full size
    $filePath = UPLOAD_DIR . $v['filename'];
    $fullSizeFilePath = UPLOAD_DIR . $gd->createName($v['filename'], '_FULLSIZE');
    unlink($filePath);
    rename($fullSizeFilePath, $filePath);
    // 2) compute the new coordinates
    $scaledSize = $gd->getProperties($filePath);
    $percentChange = $scaledSize['w'] / 500;
    // we know we scaled by width of 500 in upload
    $newCoords = array('x' => $v['x'] * $percentChange, 'y' => $v['y'] * $percentChange, 'w' => $v['w'] * $percentChange, 'h' => $v['h'] * $percentChange);
    // 3) crop the full size image
    $gd->crop($filePath, $newCoords['x'], $newCoords['y'], $newCoords['w'], $newCoords['h']);
    // 4) resize the cropped image to whatever size we need (lets go with 200 wide)
    $ar = $gd->getAspectRatio($newCoords['w'], $newCoords['h'], 200, 0);
    $gd->resize($filePath, $ar['w'], $ar['h']);
}
echo "1";
示例#4
0
I have altered the fileuploader.php to pass back the filename 
which was set and the original filename
*/
require "../scripts" . DS . "fileuploader" . DS . "fileuploader.php";
$allowedExtensions = array('jpeg', 'jpg', 'gif', 'png');
$sizeLimit = 2 * 1024 * 1024;
// max file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload(UPLOAD_DIR, false, md5(uniqid()));
//handleUpload($uploadDirectory, $replaceOldFile=FALSE, $filename='')
/* 
For your crop you should:
1) Make a copy of the full size original
2) Scale down or up this image so it fits in the browser nicely
3) When the crop occurs we will manipulate the full size image
*/
require "gd_image.php";
$gd = new GdImage();
// step 1: make a copy of the original
$filePath = UPLOAD_DIR . $result['filename'];
$copyName = $gd->createName($result['filename'], '_FULLSIZE');
$gd->copy($filePath, UPLOAD_DIR . $copyName);
// step 2: Scale down or up this image so it fits in the browser nicely, lets say 500px is safe
$oldSize = $gd->getProperties($filePath);
$newSize = $gd->getAspectRatio($oldSize['w'], $oldSize['h'], 500, 0);
$gd->resize($filePath, $newSize['w'], $newSize['h']);
// step 3: handled in crop.php!
// to pass data through iframe you will need to encode all html tags
echo json_encode($result);
exit;