Subversion Repositories Sites.tela-botanica.org

Rev

Rev 415 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 415 Rev 434
Line 1... Line 1...
1
<?php
1
<?php
2
    
-
 
-
 
2
// Vérification de la présence d'un chemin vers l'image    
3
if($_GET['img'] == "")
3
if($_GET['img'] == '') {
4
exit;
4
	exit;
-
 
5
}
5
	
6
 
-
 
7
// Récupération de paramêtres
6
$_image_ = urldecode( $_GET['img'] );
8
$_image_ = urldecode( $_GET['img'] );
7
 
-
 
-
 
9
$_dossier = dirname($_image_).'/cache/';
-
 
10
$_fichier = pathinfo($_image_);
-
 
11
$_fichier['filename'] = trim(basename($_image_, $_fichier['extension']), '.');
8
$_width_min_ = intval($_GET['width']);
12
$_width_min_ = intval($_GET['width']);
9
$_height_min_ = intval($_GET['height']);
13
$_height_min_ = intval($_GET['height']);
10
$_quality_ = intval($_GET['quality']);
14
$_quality_ = intval($_GET['quality']);
-
 
15
$_centrage = false;
-
 
16
if (isset($_GET['centrage'])) {
-
 
17
	$_centrage = (bool)$_GET['centrage'];
-
 
18
}
11
 
19
 
-
 
20
// Création du dossier de cache
12
$new_w = $_width_min_;
21
if (!is_dir($_dossier)) {
13
$imagedata = getimagesize($_image_);
22
	mkdir($_dossier);
14
 
23
}
-
 
24
// Création du nom du fichier de cache
-
 
25
$fichier_cache = $_dossier.$_fichier['filename'].'_w'.$_width_min_.'_q'.$_quality_.'.'.$_fichier['extension'];
-
 
26
// Recherche de la présence d'une image en cache ou création de celle-ci
-
 
27
if (file_exists($fichier_cache)) {
-
 
28
	switch (strtolower($_fichier['extension'])) {
-
 
29
		case 'jpg' :
-
 
30
			header('Content-type: image/jpg');
-
 
31
			Imagejpeg(ImageCreateFromJpeg($fichier_cache));
-
 
32
			break;
-
 
33
		case 'gif' :
-
 
34
			header('Content-type: image/gif');
-
 
35
			Imagegif(ImageCreateFromGif($fichier_cache));
-
 
36
			break;
-
 
37
		case 'png' :
-
 
38
			header('Content-type: image/png');
-
 
39
			Imagepng(ImageCreateFromPng($fichier_cache));
-
 
40
			break;
-
 
41
	}
-
 
42
} else {
-
 
43
	// Calcul de la hauteur et de la largeur
-
 
44
	$info = getimagesize($_image_);
15
if(!$imagedata[0])
45
	if ($info[0] == '') {
16
exit();
46
		exit();	
17
 
47
	}
-
 
48
	$new_w = $_width_min_;
18
$new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));
49
	$new_h = (int)($info[1]*($new_w/$info[0]));
19
 
-
 
20
if(($_height_min_) AND ($new_h > $_height_min_)) {
50
	if(($_height_min_) AND ($new_h > $_height_min_)) {
21
	$new_h = $_height_min_;
51
		$new_h = $_height_min_;
22
	$new_w = (int)($imagedata[0]*($new_h/$imagedata[1]));
52
		$new_w = (int)($info[0]*($new_h/$info[1]));
-
 
53
	}
-
 
54
	
-
 
55
	// Définition des points d'origine de destination
-
 
56
	$dst_x = 0;
-
 
57
	$dst_y = 0;
-
 
58
	$dst_l = $new_w;
-
 
59
	$dst_h = $new_h;
-
 
60
	if ($_centrage != false) {
-
 
61
		$dst_x = (int)(($_width_min_ - $new_w) / 2);
-
 
62
		$dst_y = (int)(($_height_min_ - $new_h) / 2);
-
 
63
		$dst_l = $_width_min_;
-
 
64
		$dst_h = $_height_min_;
23
}
65
	}
24
 
66
	
-
 
67
	// Création de l'image
25
if(strtolower(substr($_image_,-3)) == "jpg") {
68
	switch (strtolower($_fichier['extension'])) {
-
 
69
		case 'jpg' :
26
  header("Content-type: image/jpg");
70
			header("Content-type: image/jpg");
27
  $dst_img=ImageCreate($new_w,$new_h);
71
			$dst_img = imagecreatetruecolor($dst_l, $dst_h);
28
  $src_img=ImageCreateFromJpeg($_image_);
72
			$c_fond = imagecolorallocate($dst_img, 255, 255, 255);
-
 
73
			imagefill($dst_img, 0, 0, $c_fond);
29
  $dst_img = imagecreatetruecolor($new_w, $new_h);
74
			$src_img = ImageCreateFromJpeg($_image_);
30
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
75
			imagecopyresampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
76
			$img_cache = Imagejpeg($dst_img, $fichier_cache, $_quality_);
31
  $img = Imagejpeg($dst_img, '', $_quality_);
77
			$img = Imagejpeg($dst_img, '', $_quality_);
32
}
78
			break;
33
 
-
 
34
if(substr($_GET['img'],-3) == "gif") {
79
		case 'gif' :
35
  header("Content-type: image/gif");
80
			header("Content-type: image/gif");
36
  $dst_img=ImageCreate($new_w,$new_h);
81
			$dst_img=ImageCreate($new_w,$new_h);
37
  $src_img=ImageCreateFromGif($_image_);  
82
			$src_img=ImageCreateFromGif($_image_);  
38
  ImagePaletteCopy($dst_img,$src_img);
83
			ImagePaletteCopy($dst_img,$src_img);
39
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
84
			ImageCopyResized($dst_img,$src_img,$dst_x,$dst_y,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
85
			$img_cache = Imagegif($dst_img, $fichier_cache, $_quality_);
40
  $img = Imagegif($dst_img,'', $_quality_);
86
			$img = Imagegif($dst_img,'', $_quality_);
41
}
87
			break;
42
 
-
 
43
if(substr($_GET['img'],-3) == "png") {
88
		case 'png' :
44
  header("Content-type: image/png");
89
			header("Content-type: image/png");
45
  $dst_img=ImageCreate($new_w,$new_h);
90
			$dst_img=ImageCreate($new_w,$new_h);
46
  $src_img=ImageCreateFromPng($_image_);  
91
			$src_img=ImageCreateFromPng($_image_);  
47
  ImagePaletteCopy($dst_img,$src_img);
92
			ImagePaletteCopy($dst_img,$src_img);
48
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
93
			ImageCopyResized($dst_img,$src_img,$dst_x,$dst_y,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
94
			$img_cache = Imagepng($dst_img, $fichier_cache, $_quality_);
49
  $img = Imagepng($dst_img,'', $_quality_);
95
			$img = Imagepng($dst_img,'', $_quality_);
-
 
96
			break;
50
}
97
	}
51
 
98
}
52
?>
99
?>
53
100