Example #1
0
function MakeThumb($srcFile, &$dstFile, $dstW, $dstH, $cenTer = null, $sameFile = null, $fixWH = null)
{
    $minitemp = GetThumbInfo($srcFile, $dstW, $dstH, $cenTer);
    list($imagecreate, $imagecopyre) = GetImagecreate($minitemp['type']);
    if (empty($minitemp) || !$imagecreate) {
        return false;
    }
    //if ((empty($sameFile) && $dstFile === $srcFile) || empty($minitemp) || !$imagecreate) return false;
    //!empty($sameFile) && $dstFile = $srcFile;
    $imgwidth = $minitemp['width'];
    $imgheight = $minitemp['height'];
    $srcX = $srcY = 0;
    if (!empty($cenTer)) {
        if ($imgwidth < $imgheight) {
            $srcY = round(($imgheight - $imgwidth) / 2);
            $imgheight = $imgwidth;
        } else {
            $srcX = round(($imgwidth - $imgheight) / 2);
            $imgwidth = $imgheight;
        }
    }
    $dstX = $dstY = 0;
    $thumb = $imagecreate($minitemp['dstW'], $minitemp['dstH']);
    $imagecopyre($thumb, $minitemp['source'], $dstX, $dstY, $srcX, $srcY, $minitemp['dstW'], $minitemp['dstH'], $imgwidth, $imgheight);
    MakeImage($minitemp['type'], $thumb, $dstFile);
    imagedestroy($thumb);
    return array($minitemp['dstW'], $minitemp['dstH']);
}
Example #2
0
function MakeThumb($srcFile, &$dstFile, $dstW, $dstH, $cenTer = null, $sameFile = null, $fixWH = null)
{
    global $db_quality;
    $minitemp = GetThumbInfo($srcFile, $dstW, $dstH, $cenTer);
    list($imagecreate, $imagecopyre) = GetImagecreate($minitemp['type']);
    if (empty($minitemp) || !$imagecreate) {
        return false;
    }
    //if ((empty($sameFile) && $dstFile === $srcFile) || empty($minitemp) || !$imagecreate) return false;
    //!empty($sameFile) && $dstFile = $srcFile;
    $imgwidth = $minitemp['width'];
    $imgheight = $minitemp['height'];
    $srcX = $srcY = 0;
    if (!empty($cenTer)) {
        $dsDivision = $imgheight / $imgwidth;
        $fixDivision = $dstH / $dstW;
        if ($dsDivision > $fixDivision) {
            $tmpimgheight = $imgwidth * $fixDivision;
            $srcY = round(($imgheight - $tmpimgheight) / 2);
            $imgheight = $tmpimgheight;
        } else {
            $tmpimgwidth = $imgheight / $fixDivision;
            $srcX = round(($imgwidth - $tmpimgwidth) / 2);
            $imgwidth = $tmpimgwidth;
        }
    }
    $dstX = $dstY = 0;
    $thumb = $imagecreate($minitemp['dstW'], $minitemp['dstH']);
    if (function_exists('ImageColorAllocate') && function_exists('ImageColorTransparent')) {
        //背景透明处理
        $black = ImageColorAllocate($thumb, 0, 0, 0);
        $bgTransparent = ImageColorTransparent($thumb, $black);
    }
    $imagecopyre($thumb, $minitemp['source'], $dstX, $dstY, $srcX, $srcY, $minitemp['dstW'], $minitemp['dstH'], $imgwidth, $imgheight);
    MakeImage($minitemp['type'], $thumb, $dstFile, $db_quality);
    imagedestroy($thumb);
    return array($minitemp['dstW'], $minitemp['dstH']);
}