~ubuntu-branches/ubuntu/utopic/tdiary/utopic

« back to all changes in this revision

Viewing changes to contrib2/util/image-gallery/js/SmoothGallery/resizer.php

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2011-04-11 21:53:16 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411215316-ih4gt4q8p29d2wf8
Tags: 3.0.1-1
* New upstream release (Closes: #542801, #594947)
* debian/control:
 - Bumped up Standards-Version to 3.9.1.
 - Updated version dependency.
* debian/tdiary-setup.rb: Followed the upstream changes, incorporating js and
  index.fcgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* ----------------------------------------------------------------
 
3
Script coming with JonDesign's SmoothGallery (http://smoothgallery.jondesign.net).
 
4
 
 
5
It is an adapted version of
 
6
http://sneak.co.nz/2006/10/27/dynamic-image-resizing/
 
7
which is itself an improvement of the original script from
 
8
Timothy Crowe's 'veryraw' website, with caching additions added by Trent Davies:
 
9
http://veryraw.com/history/2005/03/image-resizing-with-php/
 
10
 
 
11
Thanks to:
 
12
Tim Novinger for finding the image extension problem (fixed by an strtolower())
 
13
---------------------------------------------------------------- */
 
14
 
 
15
$max_height = 1000;
 
16
$max_width = 2000;
 
17
if (isset($_GET["imgfile"]))
 
18
{
 
19
        if (function_exists(get_magic_quotes_gpc) && get_magic_quotes_gpc())
 
20
        {
 
21
            $image = stripslashes( $_GET["imgfile"] );
 
22
        } else  $image = $_GET["imgfile"];
 
23
        if (isset($_GET["max_width"])) { if($_GET["max_width"] < 2000) $max_width = $_GET["max_width"]; }
 
24
        if (isset($_GET["max_height"])) { if($_GET["max_height"] < 1000) $max_height = $_GET["max_height"]; }
 
25
        
 
26
        if (strrchr($image, '/')) {
 
27
                $filename = substr(strrchr($image, '/'), 1); // remove folder references
 
28
        } else {
 
29
                $filename = $image;
 
30
        }
 
31
        
 
32
        $size = getimagesize($image);
 
33
        $width = $size[0];
 
34
        $height = $size[1];
 
35
        
 
36
        // get the ratio needed
 
37
        $x_ratio = $max_width / $width;
 
38
        $y_ratio = $max_height / $height;
 
39
        
 
40
        // if image already meets criteria, load current values in
 
41
        // if not, use ratios to load new size info
 
42
        if (($width <= $max_width) && ($height <= $max_height) ) {
 
43
                $tn_width = $width;
 
44
                $tn_height = $height;
 
45
        } else if (($x_ratio * $height) < $max_height) {
 
46
                $tn_height = ceil($x_ratio * $height);
 
47
                $tn_width = $max_width;
 
48
        } else {
 
49
                $tn_width = ceil($y_ratio * $width);
 
50
                $tn_height = $max_height;
 
51
        }
 
52
        
 
53
        /* Caching additions by Trent Davies */
 
54
        // first check cache
 
55
        // cache must be world-readable
 
56
        $resized = 'cache/'.$tn_width.'x'.$tn_height.'-'.$filename;
 
57
        $imageModified = @filemtime($image);
 
58
        $thumbModified = @filemtime($resized);
 
59
        
 
60
        header("Content-type: image/jpeg");
 
61
        
 
62
        // if thumbnail is newer than image then output cached thumbnail and exit
 
63
        if($imageModified<$thumbModified) {
 
64
                header("Last-Modified: ".gmdate("D, d M Y H:i:s",$thumbModified)." GMT");
 
65
                readfile($resized);
 
66
                exit;
 
67
        }
 
68
        
 
69
        // read image
 
70
        $ext = strtolower(substr(strrchr($image, '.'), 1)); // get the file extension
 
71
        switch ($ext) { 
 
72
                case 'jpg':     // jpg
 
73
                        $src = imagecreatefromjpeg($image) or notfound();
 
74
                        break;
 
75
                case 'png':     // png
 
76
                        $src = imagecreatefrompng($image) or notfound();
 
77
                        break;
 
78
                case 'gif':     // gif
 
79
                        $src = imagecreatefromgif($image) or notfound();
 
80
                        break;
 
81
                default:
 
82
                        notfound();
 
83
        }
 
84
        
 
85
        // set up canvas
 
86
        $dst = imagecreatetruecolor($tn_width,$tn_height);
 
87
        
 
88
        imageantialias ($dst, true);
 
89
        
 
90
        // copy resized image to new canvas
 
91
        imagecopyresampled ($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
 
92
        
 
93
        /* Sharpening adddition by Mike Harding */
 
94
        // sharpen the image (only available in PHP5.1)
 
95
        /*if (function_exists("imageconvolution")) {
 
96
                $matrix = array(    array( -1, -1, -1 ),
 
97
                            array( -1, 32, -1 ),
 
98
                            array( -1, -1, -1 ) );
 
99
                $divisor = 24;
 
100
                $offset = 0;
 
101
        
 
102
                imageconvolution($dst, $matrix, $divisor, $offset);
 
103
        }*/
 
104
        
 
105
        // send the header and new image
 
106
        imagejpeg($dst, null, 90);
 
107
        imagejpeg($dst, $resized, 90); // write the thumbnail to cache as well...
 
108
        
 
109
        // clear out the resources
 
110
        imagedestroy($src);
 
111
        imagedestroy($dst);
 
112
}
 
113
?>
 
 
b'\\ No newline at end of file'