Beispiel #1
0
function createThumb($source, $destination, $saveName, $targetWidth, $targetHeight)
{
    // Get image size
    $originalSize = getimagesize($source);
    // Set thumb image size
    $targetSize = setWidthHeight($originalSize[0], $originalSize[1], $targetWidth, $targetHeight);
    // Get image extension
    $ext = getExtension($source);
    // Determine source image type
    if ($ext == 'gif') {
        $src = imagecreatefromgif($source);
    } elseif ($ext == 'png') {
        $src = imagecreatefrompng($source);
    } elseif ($ext == 'jpg' || $ext == 'jpeg') {
        $src = imagecreatefromjpeg($source);
    } else {
        return 'Unknow image type !';
    }
    // Copy image
    $dst = imagecreatetruecolor($targetSize[0], $targetSize[1]);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $targetSize[0], $targetSize[1], $originalSize[0], $originalSize[1]);
    if (!file_exists($destination)) {
        if (!createRDir($destination)) {
            return 'Unabled to create destination folder !';
        }
    }
    // destination + fileName
    $thumbName = $destination . '/' . $saveName . '.' . $ext;
    if ($ext == 'gif') {
        imagegif($dst, $thumbName);
    } else {
        if ($ext == 'png') {
            imagepng($dst, $thumbName);
        } else {
            if ($ext == 'jpg' || $ext == 'jpeg') {
                imagejpeg($dst, $thumbName, 100);
            } else {
                return 'Fail to create thumb !';
            }
        }
    }
    imagedestroy($dst);
    imagedestroy($src);
    return $thumbName;
}
Beispiel #2
0
 public function qrcodeAction()
 {
     $value = $this->get('value', FALSE);
     if ($value) {
         Yaf_Loader::import('L_Qrcode.class.php');
         $savePath .= APP_PATH . '/public/qrcode';
         if (!file_exists($savePath)) {
             Helper::import('File');
             createRDir($savePath);
         }
         $err = 'L';
         $size = '10';
         // 有 LOGO 的话去掉下一行的注释, 并作为构造函数的第五个参数传入
         //$logo = APP_PATH.'/asset/logo.jpg';
         Helper::import('String');
         $file = getRandom(6, 1) . '.png';
         $qr = $savePath . '/' . $file;
         $Qrcode = new L_Qrcode($value, $qr, $err, $size);
         $Qrcode->createQr();
         $buffer['qrCode'] = '/qrcode/' . $file;
     }
     $this->getView()->assign($buffer);
 }
Beispiel #3
0
 * File: uploadify.php
 * Functionality: Uploadify 的上传处理文件
 * Author: Nic XIE
 * Date: 2013-07-01
 */
define('BASE_PATH', $_SERVER['DOCUMENT_ROOT']);
include BASE_PATH . '/common.php';
Helper::import('File');
// Destination
$targetFolder = getParam('destination');
$id = getParam('id');
$is_insert_db = getParam('is_insert_db');
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = UPLOAD_PATH . '/' . $targetFolder;
    // 保存文件的目标文件夹
    if (!file_exists($targetPath)) {
        @createRDir($targetPath);
    }
    // Validate the file type
    $fileTypes = array('jpg', 'jpeg', 'gif', 'png');
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    $name = uniqid() . '.' . $fileParts['extension'];
    $targetFile = $targetPath . '/' . $name;
    if (in_array($fileParts['extension'], $fileTypes)) {
        move_uploaded_file($tempFile, $targetFile);
        echo $name;
    } else {
        echo 'Error when uploading file !2';
    }
}