Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/showthumb.php,v $
15
  $Revision: 1.6 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
define('IN_COPPERMINE', true);
21
define('SHOWTHUMB_PHP', true);
22
 
23
require("include/init.inc.php");
24
 
25
if (!GALLERY_ADMIN_MODE) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
26
 
27
define("GIS_GIF", 1);
28
define("GIS_JPG", 2);
29
define("GIS_PNG", 3);
30
 
31
define("UNKNOW_ICON", 'images/unk48x48.gif');
32
define("GIF_ICON", 'images/gif48x48.gif');
33
define("READ_ERROR_ICON", 'images/read_error48x48.gif');
34
 
35
function makethumbnail($src_file, $newSize, $method)
36
{
37
    global $CONFIG;
38
 
39
    $content_type = array(
40
        GIS_GIF => 'gif',
41
        GIS_JPG => 'jpeg',
42
        GIS_PNG => 'png'
43
        );
44
    // Checks that file exists and is readable
45
    if (!filesize($src_file) || !is_readable($src_file)) {
46
        header("Content-type: image/gif");
47
        fpassthru(fopen(READ_ERROR_ICON, 'rb'));
48
        exit;
49
    }
50
    // find the image size, no size => unknow type
51
    $imginfo = getimagesize($src_file);
52
    if ($imginfo == null) {
53
        header("Content-type: image/gif");
54
        fpassthru(fopen(UNKNOW_ICON, 'rb'));
55
        exit;
56
    }
57
    // GD can't handle gif images
58
    if ($imginfo[2] == GIS_GIF && ($method == 'gd1' || $method == 'gd2')) {
59
        header("Content-type: image/gif");
60
        fpassthru(fopen(GIF_ICON, 'rb'));
61
        exit;
62
    }
63
    // height/width
64
    $srcWidth = $imginfo[0];
65
    $srcHeight = $imginfo[1];
66
 
67
    $ratio = max($srcWidth, $srcHeight) / $newSize;
68
    $ratio = max($ratio, 1.0);
69
    $destWidth = (int)($srcWidth / $ratio);
70
    $destHeight = (int)($srcHeight / $ratio);
71
    // Choose method for thumb creation
72
    switch ($method) {
73
        case "im" :
74
            if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
75
                $cur_dir = dirname(__FILE__);
76
                $src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
77
            } else {
78
                $src_file = escapeshellarg($src_file);
79
            }
80
            header("Content-type: image/" . ($content_type[$imginfo[2]]));
81
            passthru("{$CONFIG['impath']}convert -quality $CONFIG[jpeg_qual] -antialias -geometry {$destWidth}x{$destHeight} $src_file -");
82
            break;
83
 
84
        case "gd2" :
85
            if ($imginfo[2] == GIS_JPG)
86
                $src_img = imagecreatefromjpeg($src_file);
87
            else
88
                $src_img = imagecreatefrompng($src_file);
89
            $dst_img = imagecreatetruecolor($destWidth, $destHeight);
90
            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight, $srcWidth, $srcHeight);
91
            header("Content-type: image/jpeg");
92
            imagejpeg($dst_img);
93
            imagedestroy($src_img);
94
            imagedestroy($dst_img);
95
            break;
96
 
97
        default :
98
            if ($imginfo[2] == GIS_JPG)
99
                $src_img = imagecreatefromjpeg($src_file);
100
            else
101
                $src_img = imagecreatefrompng($src_file);
102
            $dst_img = imagecreate($destWidth, $destHeight);
103
            imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight, $srcWidth, $srcHeight);
104
            header("Content-type: image/jpeg");
105
            imagejpeg($dst_img);
106
            imagedestroy($src_img);
107
            imagedestroy($dst_img);
108
            break;
109
    }
110
}
111
 
112
makethumbnail($CONFIG['fullpath'] . $HTTP_GET_VARS['picfile'], $HTTP_GET_VARS['size'], $CONFIG['thumb_method']);
113
 
114
?>