Exemplo n.º 1
0
 public function handleUploadImgAction()
 {
     Yaf_Dispatcher::getInstance()->disableView();
     Yaf_loader::import(LIB_PATH . '/L_Upload.class.php');
     $obj = new L_Upload();
     //实例化上传类
     $obj->maxSize = 1000000;
     //图片最大上传大小
     $obj->savePath = getcwd() . '/Uploads/new/';
     //图片保存路径
     $obj->saveRule = 'uniqid';
     //保存文件名
     $obj->uploadReplace = true;
     //是否覆盖同名文件 是
     $obj->allowExts = array(0 => 'jpg', 1 => 'jpeg', 2 => 'gif', 3 => 'png');
     //允许上传文件后缀名
     $obj->thumb = false;
     //生成缩略图
     $obj->autoSub = true;
     //使用子目录保存上传文件
     $obj->subType = 'date';
     //使用日期为子目录名称
     $obj->dateFormat = 'Y_m_d';
     //使用年-月形式
     if (!$obj->upload()) {
         echo json_encode(array('status' => 0, 'msg' => $obj->getErrorMsg()));
         die;
     } else {
         $info = $obj->getUploadFileInfo();
         $pic = explode('/', $info[0]['savename']);
         $return = array('status' => 1, 'path' => '/Uploads/new/' . $pic[0] . '/' . $pic[1]);
         //压缩图片
         image_png_size_add(getcwd() . '/Uploads/new/' . $pic[0] . '/' . $pic[1], getcwd() . '/Uploads/new/' . $pic[0] . '/' . $pic[1]);
         echo json_encode($return);
         die;
     }
 }
Exemplo n.º 2
0
<?php

$imgsrc = "aa.gif";
$limit_width = 640;
//$percent_num=70;
//$imgsrc="aa.gif";
if (!empty($_GET['i'])) {
    $imgsrc = $_GET['i'];
}
if (!empty($_GET['w'])) {
    $limit_width = $_GET['w'];
}
image_png_size_add($imgsrc, $limit_width);
function image_png_size_add($imgsrc, $limit_width)
{
    list($width, $height, $type) = getimagesize($imgsrc);
    $percent = $limit_width / $width;
    //ͼƬѹËõ±È
    if ($width <= 220) {
        $percent = 1;
    }
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    switch ($type) {
        case 1:
            header('Content-Type:image/gif');
            $giftype = check_gifcartoon($imgsrc);
            if ($giftype) {
                $image_wp = imagecreatetruecolor($new_width, $new_height);
                $image = imagecreatefromgif($imgsrc);
                imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
Exemplo n.º 3
0
<?php

$imgsrc = "aa.gif";
$percent_num = 70;
//$imgsrc="aa.gif";
if (!empty($_GET['i'])) {
    $imgsrc = $_GET['i'];
}
if (!empty($_GET['p'])) {
    $percent_num = $_GET['p'];
}
image_png_size_add($imgsrc, $percent_num);
function image_png_size_add($imgsrc, $percent_num = 60)
{
    list($width, $height, $type) = getimagesize($imgsrc);
    $percent = $percent_num / 100;
    //ͼƬѹËõ±È
    if ($width <= 220) {
        $percent = 1;
    }
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    switch ($type) {
        case 1:
            header('Content-Type:image/gif');
            $giftype = check_gifcartoon($imgsrc);
            if ($giftype) {
                $image_wp = imagecreatetruecolor($new_width, $new_height);
                $image = imagecreatefromgif($imgsrc);
                imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                imagejpeg($image_wp);