示例#1
0
function create_thumbnail($targetPath, $targetFile, $sourceFile, $widthNew, $heightNew, $qualityNew)
{
    $imgsize = getimagesize($targetFile);
    switch (strtolower(substr($targetFile, -3))) {
        case "jpg":
            $image = imagecreatefromjpeg($targetFile);
            break;
        case "png":
            $image = imagecreatefrompng($targetFile);
            break;
        case "gif":
            $image = imagecreatefromgif($targetFile);
            break;
        default:
            exit;
            break;
    }
    $width = $widthNew;
    // New width of image
    $height = $heightNew;
    // New height of image
    // Original size
    $src_w = $imgsize[0];
    $src_h = $imgsize[1];
    // Create new size
    if ($widthNew && $src_w < $src_h) {
        $width = $heightNew / $src_h * $src_w;
    } else {
        $height = $widthNew / $src_w * $src_h;
    }
    $picture = imagecreatetruecolor($width, $height);
    imagealphablending($picture, false);
    imagesavealpha($picture, true);
    $bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
    // Sharpen Image
    $picture = Image_Sharpen($picture, 80, 0.5, 3);
    if ($bool) {
        switch (strtolower(substr($targetFile, -3))) {
            case "jpg":
                $bool2 = imagejpeg($picture, $targetPath . "/" . $sourceFile, $qualityNew);
                break;
            case "png":
                imagepng($picture, $targetPath . "/" . $sourceFile);
                break;
            case "gif":
                imagegif($picture, $targetPath . "/" . $sourceFile);
                break;
        }
    }
    imagedestroy($picture);
    imagedestroy($image);
}
示例#2
0
文件: image.php 项目: dimadmb/100shub
function Image_Resize($file, $size, $jpg_quality)
{
    $width = $size;
    $height = $size;
    // Neue Bildgröße und Typ ermitteln
    list($width_orig, $height_orig, $type) = @getimagesize($file);
    // Neue Bildgröße und Typ brechnen
    if ($width_orig > $width || $height_orig > $height) {
        $ratio_orig = $width_orig / $height_orig;
        if ($width / $height > $ratio_orig) {
            $width = $height * $ratio_orig;
        } else {
            $height = $width / $ratio_orig;
        }
    } else {
        $width = $width_orig;
        $height = $height_orig;
    }
    // Neues Bild erstellen
    $image_p = imagecreatetruecolor($width, $height);
    switch ($type) {
        case 1:
            if (ImageTypes() & IMG_GIF) {
                // Bilddatei laden
                $image = imagecreatefromgif($file);
                // Transparenz erhalten
                $trnprt_indx = imagecolortransparent($image);
                if ($trnprt_indx >= 0) {
                    $trnprt_color = @imagecolorsforindex($image, $trnprt_indx);
                    $trnprt_indx = @imagecolorallocate($image_p, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                    imagefill($image_p, 0, 0, $trnprt_indx);
                    imagecolortransparent($image_p, $trnprt_indx);
                }
                // Resample
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
                // Bild schärfen
                $image_p = Image_Sharpen($image_p, 80, 0.5, 3);
                // Bilddatei speichern
                @imagegif($image_p, $file);
            } else {
                //
            }
            break;
        case 2:
            if (ImageTypes() & IMG_JPG) {
                // Bilddatei laden
                $image = imagecreatefromjpeg($file);
                // Resample
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
                // Bild schärfen
                $image_p = Image_Sharpen($image_p, 80, 0.5, 3);
                // Bilddatei speichern
                @imagejpeg($image_p, $file, $jpg_quality);
            } else {
                //
            }
            break;
        case 3:
            if (ImageTypes() & IMG_PNG) {
                // Bilddatei laden
                $image = imagecreatefrompng($file);
                // Transparenz erhalten
                imagealphablending($image_p, false);
                $colorTransparent = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
                imagefill($image_p, 0, 0, $colorTransparent);
                imagesavealpha($image_p, true);
                // Resample
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
                // Bild schärfen
                $image_p = Image_Sharpen($image_p, 80, 0.5, 3);
                // Bilddatei speichern
                @imagepng($image_p, $file);
            } else {
                //
            }
            break;
        default:
            //
            break;
    }
    // Speicher freigeben
    if (isset($image)) {
        imagedestroy($image);
    }
    if (isset($image_p)) {
        imagedestroy($image_p);
    }
}
示例#3
0
function create_thumbnail_watermark($targetPath, $targetFile, $sourceFile, $widthNew, $heightNew, $qualityNew)
{
    $imgsize = getimagesize($targetFile);
    switch (strtolower(substr($targetFile, -3))) {
        case "jpg":
            $image = imagecreatefromjpeg($targetFile);
            break;
        case "png":
            $image = imagecreatefrompng($targetFile);
            break;
        case "gif":
            $image = imagecreatefromgif($targetFile);
            break;
        default:
            exit;
            break;
    }
    $width = $widthNew;
    //New width of image
    $height = $heightNew;
    //New height of image
    // Original size
    $src_w = $imgsize[0];
    $src_h = $imgsize[1];
    // Create new size
    if ($widthNew && $src_w < $src_h) {
        $width = $heightNew / $src_h * $src_w;
    } else {
        $height = $widthNew / $src_w * $src_h;
    }
    imagealphablending($image, true);
    $picture = imagecreatetruecolor($width, $height);
    imagealphablending($picture, true);
    imagesavealpha($picture, true);
    imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
    // Sharpen Image
    $picture = Image_Sharpen($picture, 80, 0.5, 3);
    // Logo check and var
    $szImgLogo = JAK_WATERMARK;
    if (stripos($szImgLogo, ".png") !== false) {
        $lpLogo = imagecreatefrompng($szImgLogo);
    } elseif (stripos($szImgLogo, ".jpg") !== false) {
        $lpLogo = imagecreatefromjpeg($szImgLogo);
    } elseif (stripos($szImgLogo, ".gif") !== false) {
        $lpLogo = imagecreatefromgif($szImgLogo);
    }
    $width_logo = imagesx($lpLogo);
    $height_logo = imagesy($lpLogo);
    if (JAK_WMPOSITION == 1) {
        $j = 0;
        $i = 0;
    } elseif (JAK_WMPOSITION == 2) {
        $j = ($width - $width_logo) / 2;
        $i = 0;
    } elseif (JAK_WMPOSITION == 3) {
        $j = $width - $width_logo;
        $i = 0;
    } elseif (JAK_WMPOSITION == 4) {
        $j = 0;
        $i = ($height - $height_logo) / 2;
    } elseif (JAK_WMPOSITION == 5) {
        $j = ($width - $width_logo) / 2;
        $i = ($height - $height_logo) / 2;
    } elseif (JAK_WMPOSITION == 6) {
        $j = $width - $width_logo;
        $i = ($height - $height_logo) / 2;
    } elseif (JAK_WMPOSITION == 7) {
        $j = 0;
        $i = $height - $height_logo;
    } elseif (JAK_WMPOSITION == 8) {
        $j = ($width - $width_logo) / 2;
        $i = $height - $height_logo;
    } else {
        $j = $width - $width_logo;
        $i = $height - $height_logo;
    }
    $bool = imagecopy($picture, $lpLogo, $j, $i, 0, 0, $width_logo, $height_logo);
    if ($bool) {
        switch (strtolower(substr($targetFile, -3))) {
            case "jpg":
                $bool2 = imagejpeg($picture, $targetPath . "/" . $sourceFile, $qualityNew);
                break;
            case "png":
                imagepng($picture, $targetPath . "/" . $sourceFile);
                break;
            case "gif":
                imagegif($picture, $targetPath . "/" . $sourceFile);
                break;
        }
    }
    imagedestroy($picture);
    imagedestroy($image);
}