Пример #1
0
function MakeThumbnail($upfiledir, $src, $tName, $tw = '', $th = '', $scale = true, $tDir = "thumb")
{
    global $iCMS;
    $R = array();
    $image = "";
    $tMap = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
    $tw = empty($tw) ? (int) $iCMS->config['thumbwidth'] : $tw;
    $th = empty($th) ? (int) $iCMS->config['thumbhight'] : $th;
    if ($tw && $th) {
        list($width, $height, $type) = @getimagesize($src);
        if ($width < 1 && $height < 1) {
            $R['width'] = $tw;
            $R['height'] = $th;
            $R['src'] = $src;
            return $R;
        }
        if ($width > $tw || $height > $th) {
            createdir($upfiledir . $tDir);
            if ($scale) {
                $im = scale_image(array("mw" => $tw, "mh" => $th, "cw" => $width, "ch" => $height));
            } else {
                $im = array('w' => $tw, 'h' => $th);
            }
            $R['width'] = $im['w'];
            $R['height'] = $im['h'];
            $tName .= '_' . $R['width'] . 'x' . $R['height'];
            $img = icf($tMap[$type], $src);
            if ($img['res']) {
                $thumb = imagecreatetruecolor($im['w'], $im['h']);
                imagecopyresampled($thumb, $img['res'], 0, 0, 0, 0, $im['w'], $im['h'], $width, $height);
                PHP_VERSION != '4.3.2' && UnsharpMask($thumb);
                $R['src'] = $upfiledir . $tDir . "/" . $tName;
                __image($thumb, $img['type'], $R['src']);
                $R['src'] .= '.' . $img['type'];
            } else {
                $R['src'] = $src;
            }
        } else {
            $R['width'] = $width;
            $R['height'] = $height;
            $R['src'] = $src;
        }
        return $R;
    }
}
Пример #2
0
     alert('源图小于或等于剪裁尺寸,不剪裁!', 'javascript:insert("' . $pic . '","' . $_POST['in'] . '");');
 }
 if ($width == $_width && $height == $_height) {
     //不对源图缩放
     $_img = icf($tMap[$type], $iPic);
     $_Type = $_img['type'];
 } else {
     $img = icf($tMap[$type], $iPic);
     $_Type = $img['type'];
     if ($img['res']) {
         $thumb = imagecreatetruecolor($_width, $_height);
         imagecopyresampled($thumb, $img['res'], 0, 0, 0, 0, $_width, $_height, $width, $height);
         $_tmpfile = $iCMS->config['uploadfiledir'] . '/crop_tmp_' . time() . rand(1, 999999);
         __image($thumb, $_Type, getfilepath($_tmpfile, iPATH, '+'));
         $_tmpfile .= '.' . $_Type;
         $_img = icf($tMap[$type], $_tmpfile);
         delfile($_tmpfile);
     }
 }
 if ($_img['res']) {
     $_thumb = imagecreatetruecolor($w, $h);
     imagecopyresampled($_thumb, $_img['res'], 0, 0, $x, $y, $w, $h, $w, $h);
     $thumbpath = substr($iPic, 0, strrpos($iPic, '/')) . "/thumb";
     $picName = substr($iPic, 0, strrpos($iPic, '.'));
     $picName = substr($picName, strrpos($picName, '/'));
     $fileName = $thumbpath . $picName . '_' . $w . 'x' . $h;
     createdir($thumbpath);
     __image($_thumb, $_img['type'], $fileName);
     $fileName .= '.' . $_Type;
     alert($pic . ' 剪裁成功!', 'javascript:insert("' . $iCMS->dir . getfilepath($fileName, iPATH, '-') . '","' . $_POST['in'] . '");');
 }