source: extensions/DynamicResize/resize.php @ 24795

Last change on this file since 24795 was 12179, checked in by arno, 13 years ago

feature : commit initial, suite

File size: 2.5 KB
Line 
1<?php
2//bool file_exists ( string $filename )
3//take parameters in priority, then, cookie, then ..todo
4
5 $missing_size=false;
6 $debug=false;
7 if (isset($_GET["picture_url"])) { $picture_url = $_GET["picture_url"];} else { die("pictureUrl parameter missing");} 
8 if (isset($_GET["width"])) { $width = $_GET["width"];} else {$width=0;}
9 if (isset($_GET["height"])) { $height = $_GET["height"];} else {$height=0;}
10 if (isset($_COOKIE["dynamic_width"])) { $dynamic_width=$_COOKIE["dynamic_width"];} 
11 if (isset($_COOKIE["dynamic_height"])) { $dynamic_height=$_COOKIE["dynamic_height"];} 
12 if (isset($_GET["dyn_width"])) {$dynamic_width=($_GET["dyn_width"]);}
13 if (isset($_GET["dyn_height"])) {$dynamic_height=($_GET["dyn_height"]);}
14 if (!isset($dynamic_width) && !isset($dynamic_height)) $missing_size=true;
15 if (isset($_GET["debug"])) $debug=$_GET["debug"];
16 $picture_path='/home/piwigo/webapp/web'.substr($picture_url,1);
17 
18 if($debug){
19        echo "pictureUrl:".$picture_url."<br/>";
20        echo "width:".$width."<br/>";
21        echo "height:".$height."<br/>";
22        echo "dynamic_width:".$dynamic_width."<br/>";
23        echo "dynamic_heigth:".$dynamic_height."<br/>"; 
24        echo "picturePath:".$picture_path."<br/>";
25 
26        list($usec, $sec) = explode(' ', microtime());
27        $script_start= (float) $sec + (float) $usec;
28}
29if($missing_size){
30        die("pictureUrl parameter missing");
31        //@todo: in a next version ,let it go ? (see test below)
32}
33
34if (extension_loaded('imagick')) {
35        $image = new Imagick($picture_path);
36        if(! $missing_size){
37                $image->adaptiveResizeImage($dynamic_width,$dynamic_height);
38        }
39        $image->setCompression(Imagick::COMPRESSION_JPEG);
40        $image->setCompressionQuality(80);
41        $image->setImageFormat('jpeg'); 
42       
43        $size = $image->getImageLength(); 
44}else{
45        //todo echo "Imagick not loaded, please check your server or contact your hosting service";
46        //try alternate method using GD
47}
48
49if(!$debug){
50        header('Content-type: image/jpeg');
51        //header('Content-Length:'.$image->getImageSize());
52        header('Content-Transfer-Encoding :binary');
53        echo $image;
54}else{
55        echo 'imageSize:'.$size.'<br/>';
56        echo 'compression;'.$image->getCompression();
57        echo 'compressionq:'.$image->getCompressionQuality();
58       
59        list($usec, $sec) = explode(' ', microtime());
60        $script_end = (float) $sec + (float) $usec;
61        $elapsed_time = round($script_end - $script_start, 5);
62        if($missing_size){
63                echo "No resize data. Please check that cookie has been set. Image <strong>NOT</strong> resized, computed in ".$elapsed_time." s<br/>";
64        }else{
65                echo "Image resized and computed in ".$elapsed_time." s<br/>";
66        }
67}
68
69?>
Note: See TracBrowser for help on using the repository browser.