Subversion Repositories Sites.tela-botanica.org

Rev

Rev 415 | Show entire file | Regard 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
}
Line -... Line 6...
-
 
6
 
5
	
7
// Récupération de paramêtres
6
$_image_ = urldecode( $_GET['img'] );
-
 
-
 
8
$_image_ = urldecode( $_GET['img'] );
-
 
9
$_dossier = dirname($_image_).'/cache/';
-
 
10
$_fichier = pathinfo($_image_);
7
 
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']);
-
 
14
$_quality_ = intval($_GET['quality']);
-
 
15
$_centrage = false;
-
 
16
if (isset($_GET['centrage'])) {
-
 
17
	$_centrage = (bool)$_GET['centrage'];
Line -... Line 18...
-
 
18
}
10
$_quality_ = intval($_GET['quality']);
19
 
11
 
20
// Création du dossier de cache
12
$new_w = $_width_min_;
21
if (!is_dir($_dossier)) {
-
 
22
	mkdir($_dossier);
-
 
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 {
13
$imagedata = getimagesize($_image_);
43
	// Calcul de la hauteur et de la largeur
14
 
44
	$info = getimagesize($_image_);
15
if(!$imagedata[0])
45
	if ($info[0] == '') {
-
 
46
		exit();	
16
exit();
47
	}
17
 
-
 
18
$new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));
48
	$new_w = $_width_min_;
19
 
49
	$new_h = (int)($info[1]*($new_w/$info[0]));
20
if(($_height_min_) AND ($new_h > $_height_min_)) {
50
	if(($_height_min_) AND ($new_h > $_height_min_)) {
-
 
51
		$new_h = $_height_min_;
-
 
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);
21
	$new_h = $_height_min_;
63
		$dst_l = $_width_min_;
Line -... Line 64...
-
 
64
		$dst_h = $_height_min_;
22
	$new_w = (int)($imagedata[0]*($new_h/$imagedata[1]));
65
	}
-
 
66
	
23
}
67
	// Création de l'image
24
 
68
	switch (strtolower($_fichier['extension'])) {
-
 
69
		case 'jpg' :
-
 
70
			header("Content-type: image/jpg");
25
if(strtolower(substr($_image_,-3)) == "jpg") {
71
			$dst_img = imagecreatetruecolor($dst_l, $dst_h);
26
  header("Content-type: image/jpg");
-
 
27
  $dst_img=ImageCreate($new_w,$new_h);
72
			$c_fond = imagecolorallocate($dst_img, 255, 255, 255);
-
 
73
			imagefill($dst_img, 0, 0, $c_fond);
28
  $src_img=ImageCreateFromJpeg($_image_);
74
			$src_img = ImageCreateFromJpeg($_image_);
29
  $dst_img = imagecreatetruecolor($new_w, $new_h);
75
			imagecopyresampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
30
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
31
  $img = Imagejpeg($dst_img, '', $_quality_);
76
			$img_cache = Imagejpeg($dst_img, $fichier_cache, $_quality_);
32
}
77
			$img = Imagejpeg($dst_img, '', $_quality_);
33
 
78
			break;
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);
-
 
82
			$src_img=ImageCreateFromGif($_image_);  
37
  $src_img=ImageCreateFromGif($_image_);  
83
			ImagePaletteCopy($dst_img,$src_img);
38
  ImagePaletteCopy($dst_img,$src_img);
84
			ImageCopyResized($dst_img,$src_img,$dst_x,$dst_y,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
39
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
40
  $img = Imagegif($dst_img,'', $_quality_);
85
			$img_cache = Imagegif($dst_img, $fichier_cache, $_quality_);
41
}
86
			$img = Imagegif($dst_img,'', $_quality_);
42
 
87
			break;
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);
-
 
91
			$src_img=ImageCreateFromPng($_image_);  
46
  $src_img=ImageCreateFromPng($_image_);  
92
			ImagePaletteCopy($dst_img,$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_);
47
  ImagePaletteCopy($dst_img,$src_img);
95
			$img = Imagepng($dst_img,'', $_quality_);
48
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
-
 
49
  $img = Imagepng($dst_img,'', $_quality_);
96
			break;