Beispiel #1
0
function makethumb($srcfile, $thumbsizearr = array(100, 100), $dstfile = '')
{
    global $_SCONFIG;
    if (empty($dstfile)) {
        $dstfile = filemain($srcfile) . '.thumb.jpg';
        //自建立缩略图
        $srcfile_file = A_DIR . '/' . $srcfile;
        $dstfile_file = A_DIR . '/' . $dstfile;
    } else {
        $srcfile_file = $srcfile;
        $dstfile_file = $dstfile;
    }
    if (!file_exists($srcfile_file)) {
        return '';
    }
    $opnotkeepscale = 4;
    $opbestresizew = 8;
    $opbestresizeh = 16;
    $option = $_SCONFIG['thumboption'];
    $cutmode = $_SCONFIG['thumbcutmode'];
    $startx = $_SCONFIG['thumbcutstartx'];
    $starty = $_SCONFIG['thumbcutstarty'];
    $dstW = intval($thumbsizearr[0]);
    $dstH = intval($thumbsizearr[1]);
    if ($dstW < 20) {
        $dstW = 100;
    }
    if ($dstH < 20) {
        $dstH = 100;
    }
    $imgtype = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
    $func_output = 'ImageJpeg';
    if (!function_exists($func_output)) {
        return '';
    }
    $data = @getimagesize($srcfile_file);
    if (!empty($data) && is_array($data) && $data[2] != 1 && $data['mime'] != 'image/gif') {
    } else {
        return '';
    }
    $func_create = "imagecreatefrom" . $imgtype[$data[2]];
    if (!function_exists($func_create)) {
        return '';
    }
    $im = @$func_create($srcfile_file);
    $srcW = @imagesx($im);
    $srcH = @imagesy($im);
    $srcX = 0;
    $srcY = 0;
    $dstX = 0;
    $dstY = 0;
    //SIZE
    if ($srcW < $dstW) {
        $dstW = $srcW;
    }
    if ($srcH < $dstH) {
        $dstH = $srcH;
    }
    if ($option & $opbestresizew) {
        $dstH = round($dstW * $srcH / $srcW);
    }
    if ($option & $opbestresizeh) {
        $dstW = round($dstH * $srcW / $srcH);
    }
    $fdstW = $dstW;
    $fdstH = $dstH;
    //CUT
    if ($cutmode != 0) {
        $srcW -= $startx;
        $srcH -= $starty;
        if ($srcW * $dstH > $srcH * $dstW) {
            $testW = round($dstW * $srcH / $dstH);
            $testH = $srcH;
        } else {
            $testH = round($dstH * $srcW / $dstW);
            $testW = $srcW;
        }
        switch ($cutmode) {
            case 1:
                $srcX = 0;
                $srcY = 0;
                break;
            case 2:
                $srcX = round(($srcW - $testW) / 2);
                $srcY = round(($srcH - $testH) / 2);
                break;
            case 3:
                $srcX = $srcW - $testW;
                $srcY = $srcH - $testH;
                break;
        }
        $srcW = $testW;
        $srcH = $testH;
        $srcX += $startx;
        $srcY += $starty;
    } else {
        if (!($option & $opnotkeepscale)) {
            if ($srcW * $dstH > $srcH * $dstW) {
                $fdstH = round($srcH * $dstW / $srcW);
                $dstY = floor(($dstH - $fdstH) / 2);
                $fdstW = $dstW;
            } else {
                $fdstW = round($srcW * $dstH / $srcH);
                $dstX = floor(($dstW - $fdstW) / 2);
                $fdstH = $dstH;
            }
            $dstX = $dstX < 0 ? 0 : $dstX;
            $dstY = $dstX < 0 ? 0 : $dstY;
            $dstX = $dstX > $dstW / 2 ? floor($dstW / 2) : $dstX;
            $dstY = $dstY > $dstH / 2 ? floor($dstH / s) : $dstY;
        }
    }
    if (function_exists("imagecopyresampled") and function_exists("imagecreatetruecolor")) {
        $func_create = "imagecreatetruecolor";
        $func_resize = "imagecopyresampled";
    } elseif (function_exists("imagecreate") and function_exists("imagecopyresized")) {
        $func_create = "imagecreate";
        $func_resize = "imagecopyresized";
    } else {
        return '';
    }
    $newim = @$func_create($dstW, $dstH);
    $black = @imagecolorallocate($newim, 0, 0, 0);
    $back = @imagecolortransparent($newim, $black);
    @imagefilledrectangle($newim, 0, 0, $dstW, $dstH, $black);
    @$func_resize($newim, $im, $dstX, $dstY, $srcX, $srcY, $fdstW, $fdstH, $srcW, $srcH);
    @$func_output($newim, $dstfile_file);
    @imagedestroy($im);
    @imagedestroy($newim);
    if (!file_exists($dstfile_file)) {
        return '';
    }
    return $dstfile;
}
Beispiel #2
0
     //检查大小
     if (empty($filearr['file'])) {
         continue;
     }
     if (!empty($allowtypearr)) {
         if ($filearr['size'] > $allowtypearr[$fileext]['maxsize']) {
             @unlink(A_DIR . '/' . $filearr['file']);
             if (!empty($filearr['thumb'])) {
                 @unlink(A_DIR . '/' . $filearr['thumb']);
             }
             continue;
         }
     }
     //数据库
     if (empty($_POST['uploadsubject1'])) {
         $_POST['uploadsubject1'] = cutstr(filemain($filearr['name']), 50);
     }
     $insertsqlarr = array('uid' => $uid, 'dateline' => $_SGLOBAL['timestamp'], 'filename' => saddslashes($filearr['name']), 'subject' => trim(shtmlspecialchars($_POST['uploadsubject1'])), 'attachtype' => $filearr['type'], 'isimage' => in_array($fileext, array('jpg', 'jpeg', 'gif', 'png')) ? 1 : 0, 'size' => $filearr['size'], 'filepath' => $filearr['file'], 'thumbpath' => $filearr['thumb'], 'hash' => $hash);
     inserttable('attachments', $insertsqlarr);
     $imagereplace['oldimageurl'][] = $imageurl;
     $imagereplace['newimageurl'][] = A_URL . '/' . $filearr['file'];
 }
 //检查是否有图片下载,并替换掉原有的图片url
 if (!empty($imagereplace)) {
     $string = preg_replace(array("/\\<(script|style|iframe)[^\\>]*?\\>.*?\\<\\/(\\1)\\>/si", "/\\<!*(--|doctype|html|head|meta|link|body)[^\\>]*?\\>/si"), '', $string);
     $string = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $string);
     $string = str_replace(array("\r", "\n", "\r\n"), '', addcslashes($string, '/"\\'));
     $getimages = implode('|', $imagereplace['newimageurl']) . '|' . $getimages;
     print <<<EOF
t<script type="text/javascript">
tparent.document.getElementById("message").innerHTML = '';