Bonjour, je me permets de vous contacter car j'ai un problème avec une fonction diaporama. La fonction marche très bien pour les images qui sont plus grandes verticalement qu'horizontalement. Je bloque donc la valeur de height à 300 grâce à l'appel de la fonction : $d=new PHPdiapo($path,$iddiapo,"classe",4, array("height"=>300));.

Le problème vient lorsque j'ai une image du style 1024 * 150. La fonction augmente automatiquement les dimensions de mon image et elle devient 1400 * 300. Ce qui sort de mes pages php.

Ce que je voudrais, c'est que le script ne modifie pas la largeur de l'image si sa longueur est égale ou supérieur à 1024, mais je voudrais ajouter en plus deux bandes blanches sur la hauteur pour que cette image fasse tout de même 300 de largeur, mais sans déformation, pour ne pas que ma page php ne bouge sans cesse en hauteur.

Je m'explique :
-si l'image fait 1024 * 450, le script me redimensionne l'image en X * 300 pour garder les proportions. Ceci fonction déjà tres bien.
-si l'image fait 200 * 500, le script me redimensionne l'image en X * 300 pour garder les proportions. Ceci fonction déjà tres bien.


-si l'image fait 1024 * 200, le script ne redimensionne pas l'image mais en revanche il ajoute deux bandes de chaque coté, soit (300 - 200 )/2 pour que l'image ait une hauteur toujours de 300 mais jamais une longeur supérieure à 1024. Là est mon probleme.



Fonction d'appel : $d=new PHPdiapo($path,$iddiapo,"classe",4, array("height"=>300));.

Code diapo :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
 
class PHPDiapo {
	var $relPath;
	var $images;
	var $id;
	var $className;
	var $transition_time=3;
	var $transition_pause;
 
	function PHPDiapo ($path,$id,$className="",$timeout=3, $attrs=array()) {
        $this->attrs = $attrs;
		$this->relPath = $path;
		$this->id = $id;
		$this->className = $className;
		if ($timeout) $this->transition_pause = $timeout;
		$this->init();
		$this->write();
		}
 
    function init() {
 
 
		$this->images=array();
		$dir = $_SERVER["PATH_TRANSLATED"];
		$dir = substr($dir,0,strrpos($dir,"/")+1);
		$dir .= $this->relPath;
      	$hdl = opendir($dir);
 
		while (false !== ($file = readdir($hdl))) {
		       if($file!="." && $file!="..") {
			   // check file extension
			   $pattern = '/\.(gif|png|jpg|jpeg)$/i';
			   if (!preg_match($pattern, $file, $matches)) continue;
			   if(is_file($dir."/".$file))
			       $this->images[]="$this->relPath/$file";
                 //$test2=$test[0];
				//$this->test = $test2;
 
		//	   $this->images[]="$this->test/1200_1.jpg";
				}
		}
	}
 
	function write() {
		$this->write_func();
		$first=$this->images[0];
		$this->write_JS_init();
		echo $this->img($first,$id=$this->id,$className=$this->className);
		$this->write_JS_launch();
	} 
 
	function write_JS_init() {
		echo  "images['".$this->id."']=new Array();\r";
		for ($i=0;$i<sizeof($this->images);$i++) {
			echo  "images['".$this->id."'][$i]=new Image();\r";
			echo  "images['".$this->id."'][$i].src=\"http://doubsoccase.free.fr/ebay/".$this->images[$i]."\";\r";
			echo  "images['".$this->id."'][$i].alt=\"".$this->get_alt($this->images[$i])."\";\r";
		}
		echo "</script>\r\r";
	}
 
 
	function write_func(){
                echo "\r<script type=\"text/javascript\">\r";
 
		static $already_write = false;
		if ($already_write) {
 
                }
                else {
 
            echo "
var FRAME_PER_SEC = 20;
function set_opacity(el, op) {
    el.style.opacity = op;
    el.style.MozOpacity = op;
    el.style.KhtmlOpacity = op;
    el.style.filter = 'alpha(opacity=' + op*100 + ')';
    el.opacity = op;
}
 
function fade_in(imageId) {
    var img = document.getElementById(imageId);
    var incr = 1/((img.transition_time/3)*FRAME_PER_SEC);
    var newOp = img.opacity+incr;
    newOp = (newOp > 1) ? 1.0 : newOp;
    set_opacity(img, newOp);
    if (newOp < 1) setTimeout('fade_in(\"'+imageId+'\")',1000/FRAME_PER_SEC);
}
 
var images = new Array();
function run_diapo(diapoId) {
    obj = document.getElementById(diapoId);
    obj.src = images[diapoId][obj.index].src;
    obj.alt = images[diapoId][obj.index].alt;
    obj.title = images[diapoId][obj.index].alt;
    obj.opacity = 0.0;
 
    fade_in(diapoId);
    obj.index+=1;
    if (obj.index >= obj.length_diapo) obj.index=0;
    obj.timeout = setTimeout('run_diapo(\"'+diapoId+'\")', obj.transition_pause * 1000);
}\r";
			$already_write = true;
		}
	}
 
	function write_JS_launch() {
		$diapoID=$this->id;
		echo "\r<script type=\"text/javascript\">\r";
		echo "obj = document.getElementById('".$diapoID."');\r";
		echo "obj.transition_time=".$this->transition_time.";\r";
		echo "obj.transition_pause=".$this->transition_pause.";\r";
		echo "obj.index=0;\r";
		echo "obj.length_diapo=images['".$diapoID."'].length;\r";
		echo "obj.timeout;\r";
 
		echo "if (obj.length_diapo > 0) run_diapo('".$diapoID."');\r";
		echo "</script>\r\r";
	}
 
	function get_alt($src) {
		#  strip path
		$txt=substr($src,strrpos($src,"/")+1);
		# strip extension
		$txt=substr($txt,0,strrpos($txt,"."));
		# strip special chars
		$tostrip=array("_",",","-");
		for ($i=0;$i<sizeof($tostrip);$i++) $txt=str_replace($tostrip[$i]," ",$txt);
		return $txt;
	}
 
	function img($src,$id="",$class="") {
        $has_link = false;
		$alt=$this->get_alt($src);
        $img = "<img id='$id'  name='$id' class='$class' alt='$alt' title='$alt' src='$src'";
        foreach($this->attrs as $key=>$value)
        {
            if ($key=="href" && !$has_link) {
                $has_link = true;
                $img = "<a href=$value>$img";
            }
            else {
                $img .= " $key='$value' ";
            }
        }
        $img .= "/>\r";
        if ($has_link) $img .= "</a>";
		return $img;
	}
 }
 
?>

Merci d'avance.