root/trunk/www/dpics.php

Revision 29, 4.0 KB (checked in by alexx, 7 years ago)

Fix dPics bug (bad copy/paste ;) )

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25include('../includes/includes.inc.php');
26
27$token = retreive_url_info($_SERVER['PHP_SELF']);
28
29$nb_arg = count($token);
30
31if($nb_arg == 5)
32    $img = array(
33        'size' => $token[1],
34        'subdir1'=> $token[2],
35        'subdir2'=> $token[3],
36        'filename' => $token[4],
37        'path' => $token[2].'/'.$token[3].'/'.$token[4]
38        );
39
40elseif($nb_arg == 4)
41    $img = array(
42                'size' => null,
43        'subdir1' => $token[1],
44        'subdir2' => $token[2],
45        'filename' => $token[3],
46                'path' => $token[1].'/'.$token[2].'/'.$token[3]
47        );
48
49if(ereg('x', $img['size']))
50{
51    list($s1, $s2) = split('x', $img['size']);
52    if(is_numeric($s1) && $s1>1)
53        $width = $s1;
54    else
55        $width = 1500;
56    if(is_numeric($s2) && $s1>1)
57        $height = $s2;
58    else
59        $height = 1125;
60}
61elseif(is_numeric($img['size']))
62{
63    $width = $img['size'];
64    $height = 1125;
65}
66else
67{
68    unset($img['size']);
69}
70
71if(file_exists(ALBUMPATH.'/'.$img['path']))
72{
73    $real_file = ALBUMPATH.'/'.$img['path'];
74}
75
76if(is_null($img['size']) || $img['size']=='0x0' || $img['size']=='0')
77{
78    header('location: /albums/'.$img['path']);
79    exit();
80}
81elseif(is_numeric($width) && is_numeric($height))
82{
83    $sized_file = ALBUMSIZEDPATH.'/'.$img['size'].'/'.$img['subdir1'].'_'.$img['subdir2'].'_'.$img['filename'];
84}
85else
86{
87    header('Location: /files/pics/nopics.png');
88    exit();
89}
90
91if($img['path'] && file_exists($real_file))
92{
93    if(!file_exists($sized_file))
94    {
95        error_log("$_DOMAIN | Creation du cache pour {$img['path']} en $width x $height");
96        if(!is_dir(ALBUMSIZEDPATH.'/'.$img['size']))
97            mkdir(ALBUMSIZEDPATH.'/'.$img['size']);
98        list($w, $h, $type, $attr) = getimagesize($real_file);
99       
100        switch($type)
101        {
102        case 3:
103            $src = imagecreatefrompng($real_file);
104            $ext = 'png';
105            break;
106        case 2:
107            $src = imagecreatefromjpeg($real_file);
108            $ext = 'jpeg';
109            break;
110        case 1:
111            $src = imagecreatefromgif($real_file);
112                        $ext = 'gif';
113                        break;
114        default:
115            header('Location: /files/pics/nopics.png');
116            exit();
117        }
118        if($src)
119        {
120            $wh_ratio = $w/$h;
121
122            if($w > $width || $h > $height)
123                if($wh_ratio > $width/$height)
124                {
125                    $image_width = $width;
126                    $image_height = floor($h*$width/$w);
127                }
128                else
129                {
130                    $image_width = floor($w*$height/$h);
131                    $image_height = $height;
132                }
133            else
134            {
135                header('location: /albums/'.$img['path']);
136                exit();
137            }
138
139            error_log("$_DOMAIN | $real_file - w:$w -> $image_width   /    h:$h -> $image_height path: $sized_file");
140
141            $image = imagecreatetruecolor ($image_width, $image_height);
142            $color_white = imagecolorallocate ( $image, 255,255,255);
143            imagefilledrectangle($image, 0,0, $image_width, $image_height, $color_white);
144            imagecopyresampled($image, $src, 0,0, 0,0, $image_width, $image_height, $w, $h);
145
146
147            switch($ext)
148            {
149            case 'jpeg':
150                imagejpeg($image, $sized_file);
151                break;
152            case 'png':
153            default:
154                imagepng($image, $sized_file);
155                break;
156            }
157        }
158    }
159    header('Location: /albums/sized/'.$img['size'].'/'.$img['subdir1'].'_'.$img['subdir2'].'_'.$img['filename']);
160    exit();
161}
162else
163{
164    header('Location: /files/pics/nopics.png');
165    exit();
166}
167
168?>
Note: See TracBrowser for help on using the browser.