Redimensionnement "à l'affichage"

Petit nouveau ! | 3 Messages

27 avr. 2011, 18:21

Bonjour,
je souhaite redimensionner à l'affichage des photos qui sont uploadées dans une base de données en taille 460x352 aussi bien les chats que sur les chatons voir page exemple : http://www.chats-persans.com/_fr/fiche. ... d_chat=236 ou bien alors je souhaite que les photos soit redimensionnées lors de l'upload.
Merci pour votre aide.

Voici le code ma page ou les photos s'affichent :

Code : Tout sélectionner

<?php header('Content-Type: text/html; charset=utf-8'); include "../admin/image.class.php"; if(!isset($_GET['lg'])) $_GLOBAL['lg'] = 'fr'; else $_GLOBAL['lg'] = $_GET['lg']; include 'php/mysql.inc.php'; include_once '../php/chatterie.inc.php'; $fiche = fiche($_GET['id']); $id = $_GET['id']; $requete = " SELECT id_chats, type_chats, img_ronde, img_carre, nom_chats, desc_chats, race_chats, dispo_chats, pere_chats, mere_chats, ligne_chats, sexe_chats, place FROM adh_chats WHERE id_chatterie = '".$id."' ORDER BY place DESC"; $result = mysql_query($requete); $m = 0; $f = 0; $c = 0; while ($tab = mysql_fetch_array($result)): //print_r($tab); if(!isset($_GET['id_chat']) AND !isset($details_c)) $details_c = @getimagesize("../upimages/".$tab['img_carre']); if(!isset($_GET['id_chat']) AND !isset($file_c)) $file_c = "../upimages/".$tab['img_carre']; if(!isset($_GET['id_chat']) AND !isset($nom)) $nom = utf8_encode($tab['nom_chats']); if(!isset($_GET['id_chat']) AND !isset($desc)) $desc = utf8_encode($tab['race_chats']); if($tab['type_chats'] != 3) $file = "../upimages/".$tab['img_ronde']; else $file = "../upimages/".$tab['img_carre']; $details = @getimagesize($file); // --------------------------------------------------------------------------------------- // fonction de redimensionnement A L'AFFICHAGE // --------------------------------------------------------------------------------------- // La FONCTION : fctaffichimage($img_Src, $W_max, $H_max) // Les parametres : // - $img_Src : URL (chemin + NOM) de l image Source // - $W_max : LARGEUR maxi finale ----> ou 0 : largeur libre // - $H_max : HAUTEUR maxi finale ----> ou 0 : hauteur libre // --------------------------------------------------------------------------------------- // Affiche : src="..." width="..." height="..." pour la balise img // Utilisation : // <img alt="" <?php fctaffichimage('repimg/monimage.jpg', 120, 100) if (file_exists($file)) { // ---------------------------------------------------- // Lit les dimensions de l'image source $img_size = GetImageSize($file); $W_file = $img_size[0]; // largeur source $H_file = $img_size[1]; // hauteur source // ---------------------------------------------------- if(!$W_max) { $W_max = 460; } if(!$H_max) { $H_max = 352; } // ---------------------------------------------------- // Teste les dimensions tenant dans la zone //$W_test = round($W_file * ($H_max / $H_file)); //$H_test = round($H_file * ($W_max / $W_file)); // ---------------------------------------------------- // si l image est plus petite que la zone if($W_file<$W_max && $H_file<$H_max) { $W = $W_file; $H = $H_file; // sinon si $W_max et $H_max non definis } elseif($W_max==0 && $H_max==0) { $W = $W_file; $H = $H_file; // sinon si $W_max libre } elseif($W_max==0) { $W = $W_test; $H = $H_max; // sinon si $H_max libre } elseif($H_max==0) { $W = $W_max; $H = $H_test; // sinon les dimensions qui tiennent dans la zone } elseif($H_test > $H_max) { $W = $W_test; $H = $H_max; } else { $W = $W_max; $H = $H_test; } // ---------------------------------------------------- } else { // si le fichier image n existe pas $W = 0; $H = 0; } // ---------------------------------------------------- // AFFICHE les dimensions optimales //echo ' src="'.$img_file.'" width="'.$W.'" height="'.$H.'"'; // Affiche : src="..." width="..." height="..." pour la balise img // --------------------------------------------------------------------------------------- if($tab['id_chats'] == $_GET['id_chat']): $file_c = "../upimages/".$tab['img_carre']; $details_c = getimagesize($file_c); $nom = utf8_encode($tab['nom_chats']); $desc = utf8_encode($tab['race_chats']); endif; if($tab['type_chats'] == "1"): $male[$m]['img'] = "<td width=\"10%\"><div align=\"center\"><a href=\"fiche.php?id=".$id."&id_chat=".$tab['id_chats']."\"><img src=\"".$file."\" width=\"".$details[0]."\" height=\"".$details[1]."\" border=\"0\" alt=\"male\" /></a></div></td>\n"; $male[$m]['desc'] = $tab['desc_chats']; $male[$m]['nom'] = $tab['nom_chats']; $male[$m]['pere'] = $tab['pere_chats']; $male[$m]['mere'] = $tab['mere_chats']; $male[$m]['ligne'] = $tab['ligne_chats']; $m++; elseif($tab['type_chats'] == "2"): $femelle[$f]['img'] = "<td width=\"10%\"><div align=\"center\"><a href=\"fiche.php?id=".$id."&id_chat=".$tab['id_chats']."\"><img src=\"".$file."\" width=\"".$details[0]."\" height=\"".$details[1]."\" border=\"0\" alt=\"femelle\"/></a></div></td>\n"; $femelle[$f]['desc'] = $tab['desc_chats']; $femelle[$f]['nom'] = $tab['nom_chats']; $femelle[$f]['pere'] = $tab['pere_chats']; $femelle[$f]['mere'] = $tab['mere_chats']; $femelle[$f]['ligne'] = $tab['ligne_chats']; $f++; elseif($tab['type_chats'] == "3" || $tab['type_chats'] == 1 || $tab['type_chats'] == 2): if($details[0]>=460 || $details[1]>=352): //echo 'redim'; $img=new image($file); $img->transformeImage('redimension',460,352); $img->sauvegarderImage2($file); $img->detruireImage(); //$details[0]=200; //$details[1]=134; endif; $retaille=$details[0]; $retaille2=$details[1]; $chaton[$c]['img'] = "<td width=\"50%\"><div align=\"center\"><img src=\"".$file."\" width=\"".$retaille."\" height=\"".$retaille2."\" border=\"0\" alt=\"chaton\"/></div></td>\n"; $chaton[$c]['desc'] =utf8_encode($tab['desc_chats']); $chaton[$c]['nom'] = $tab['nom_chats']; $chaton[$c]['pere'] = $tab['pere_chats']; $chaton[$c]['mere'] = $tab['mere_chats']; $chaton[$c]['ligne'] = $tab['ligne_chats']; $chaton[$c]['sexe'] = $tab['sexe_chats']; if($tab['dispo_chats'] == 0): $chaton[$c]['dispo_msg'] = "Non disponible"; $chaton[$c]['dispo_img'] = "../images/not_dispo.gif"; elseif($tab['dispo_chats'] == 1): $chaton[$c]['dispo_msg'] = "Disponible"; $chaton[$c]['dispo_img'] = "../images/dispo.gif"; endif; $c++; endif; endwhile; $messageok = 0; if($_POST['text']!=''): if (eregi("\n",$_POST['mail']) OR eregi("\r",$_POST['mail']) OR eregi('Content-Type',$_POST['mail']) OR eregi('Content-Type',$_POST['text'])): exit('SPAM Erreur Injection'); endif; $headers = "Content-Type:text/plai; charset=utf-8\n" ."From:".$_POST['mail']; @mail("[email protected]", "[Chats-Persans] Message d'un visiteur", $_POST['text'], $headers); @mail($fiche['email_chatterie'], "[Chats-Persans] Message d'un visiteur", $_POST['text'], $headers); $messageok = 1; endif; $_SITE['lang'] = 'fr'; include '_include/head.php'; include '_include/header.php'; ?> <table style="clear:both;width:80%;margin:10px auto;" border="0" align="center" cellspacing="0"> <tr> <td colspan="2"><table width="100%" border="0"> <tr> <td width="38%" align="center" valign="middle"><span class="Style2"> <?php /*echo $fiche['nom_chatterie'][0];*/ ?> </span><span class="Style2"></span><span class="Style5"><?php echo utf8_encode($fiche['nom_chatterie']); ?></span></td> <td width="12%" align="center" valign="middle"><div align="center"><a href="france.php"><img src="../images/drapeaux/france.jpg" width="61" height="64" border="0" /></a></div></td> <td width="50%" align="center" valign="middle"><div align="center"><a href="index.php"><img src="../images/logo_small.gif" width="350" height="52" border="0" /></a></div></td> </tr> </table></td> </tr> <tr> <td width="40%" valign="top">&nbsp;</td> <td>&nbsp;</td> </tr> <tr align="center" valign="middle"> <td colspan="2"><div align="center"> <table width="100%" border="0" cellspacing="0"> <tr> <td width="10%" bgcolor="#54ADFF" class="soustitre"><?php echo $lang['fr']['Males']; ?></td> <td class="type">&nbsp;</td> <td width="10%" bgcolor="#54ADFF" class="soustitre"><?php echo $lang['fr']['Femelles']; ?></td> </tr> <tr> <?php echo $male1 = isset($male[0]['img']) ? $male[0]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> <td rowspan="6" align="center" valign="middle"><div align="center"> <table width="100%" border="0"> <tr> <td><div align="center"><img src="<?=$file_c;?>" width="<?=$details_c[0];?>" height="<?=$details_c[1];?>" /></div></td> </tr> <tr> <td><div align="center"><span class="rub_black"> <?=$nom;?> <br /> </span> <?=$desc;?> </div></td> </tr> </table> </div></td> <?php echo $femelle1 = isset($femelle[0]['img']) ? $femelle[0]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr> <?php echo $male2 = isset($male[1]['img']) ? $male[1]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; echo $femelle2 = isset($femelle[1]['img']) ? $femelle[1]['img'] : "<td width=\"10%\"><div align=\"center\"></div></td>\n"; ?> </tr> <tr> <?php echo $male3 = isset($male[2]['img']) ? $male[2]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; echo $femelle3 = isset($femelle[2]['img']) ? $femelle[2]['img'] : "<td width=\"10%\"><div align=\"center\"></div></td>\n"; ?> </tr> <tr> <?php echo $male4 = isset($male[3]['img']) ? $male[3]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; echo $femelle4 = isset($femelle[3]['img']) ? $femelle[3]['img'] : "<td width=\"10%\"><div align=\"center\"></div></td>\n"; ?> </tr> <tr> <?php echo $male5 = isset($male[4]['img']) ? $male[4]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; echo $femelle5 = isset($femelle[4]['img']) ? $femelle[4]['img'] : "<td width=\"10%\"><div align=\"center\"></div></td>\n"; ?> </tr> <tr> <?php echo $male6 = isset($male[5]['img']) ? $male[5]['img'] : "<td width=\"10%\"><div align=\"center\">&nbsp;</div></td>\n"; echo $femelle6 = isset($femelle[5]['img']) ? $femelle[5]['img'] : "<td width=\"10%\"><div align=\"center\"></div></td>\n"; ?> </tr> </table> </div></td> </tr> <tr> <td valign="top">&nbsp;</td> <td>&nbsp;</td> </tr> <?php if(isset($chaton) AND count($chaton) != 0) : ?> <tr bgcolor="#C1E1FF"> <td colspan="2"><?php echo $lang['fr']['Chatons']; ?></td> </tr> <tr> <td colspan="2" valign="top"><table width="100%"> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton1 = isset($chaton[0]['img']) ? $chaton[0]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton1 = isset($chaton[0]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[0]['nom'])."</span><br />".($chaton[0]['desc'])."\n" : null;?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton1 = isset($chaton[0]['dispo_msg']) ? "<strong><img src=\"".$chaton[0]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[0]['dispo_msg']."</strong>\n" : null; ?></td> </tr> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton2 = isset($chaton[1]['img']) ? $chaton[1]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton2 = isset($chaton[1]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[1]['nom'])."</span><br />".($chaton[1]['desc'])."\n" : null; ?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton2 = isset($chaton[1]['dispo_msg']) ? "<strong><img src=\"".$chaton[1]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[1]['dispo_msg']."</strong></tr>\n" : null; ?></td> </tr> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton2 = isset($chaton[2]['img']) ? $chaton[2]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton2 = isset($chaton[2]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[2]['nom'])."</span><br />".($chaton[2]['desc'])."\n" : null; ?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton2 = isset($chaton[2]['dispo_msg']) ? "<strong><img src=\"".$chaton[2]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[2]['dispo_msg']."</strong></tr>\n" : null; ?></td> </tr> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton2 = isset($chaton[3]['img']) ? $chaton[3]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton2 = isset($chaton[3]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[3]['nom'])."</span><br />".($chaton[3]['desc'])."\n" : null; ?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton2 = isset($chaton[3]['dispo_msg']) ? "<strong><img src=\"".$chaton[3]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[3]['dispo_msg']."</strong></tr>\n" : null; ?></td> </tr> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton2 = isset($chaton[4]['img']) ? $chaton[4]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton2 = isset($chaton[4]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[4]['nom'])."</span><br />".($chaton[4]['desc'])."\n" : null; ?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton2 = isset($chaton[4]['dispo_msg']) ? "<strong><img src=\"".$chaton[4]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[4]['dispo_msg']."</strong></tr>\n" : null; ?></td> </tr> <tr> <td><br /></td> </tr> <tr align="center"> <?php echo $chaton2 = isset($chaton[5]['img']) ? $chaton[5]['img'] : "<td width=\"100%\"><div align=\"center\">&nbsp;</div></td>\n"; ?> </tr> <tr align="center"> <td><?php echo $nom_chaton2 = isset($chaton[5]['nom']) ? "<span class=\"rub_black\">".utf8_encode($chaton[5]['nom'])."</span><br />".($chaton[5]['desc'])."\n" : null; ?></td> </tr> <tr align="center"> <td><?php echo $statu_chaton2 = isset($chaton[5]['dispo_msg']) ? "<strong><img src=\"".$chaton[5]['dispo_img']."\" width=\"14\" height=\"14\" />&nbsp;".$chaton[5]['dispo_msg']."</strong></tr>\n" : null; ?></td> </tr> </table></td> </tr> <?php endif; ?> <tr> <td valign="top" bgcolor="#54ADFF" class="soustitre">Description</td> <td>&nbsp;</td> </tr> <tr> <td colspan="2" valign="top"><p align="justify">&nbsp;</p> <p align="justify"><?php echo (utf8_encode($fiche['desc'.$_GLOBAL['lg'].'_chatterie'])); ?></p> <p align="justify"><br /> <span class="bold_underline"><?php echo $lang['fr']['Petit_com']; ?></span></p> <?php if(isset($male)): ?> <p><span class="rub_blue"><?php echo utf8_encode($lang['fr']['nosmales']); ?></span></p> <?php for($i=0;$i<4;$i++): // MALE if(isset($male[$i]['nom']) && $male[$i]['nom'] != ''): ?> <p><span class="rub_black"><?php echo utf8_decode($male[$i]['nom']); ?><br /> </span><?php echo utf8_encode($male[$i]['desc']); ?><br /> <?php if(isset($male[$i]['pere']) && $male[$i]['pere'] != ''): ?> P&egrave;re : <?php echo utf8_encode($male[$i]['pere']); ?><br /> <?php endif; if(isset($male[$i]['mere']) && $male[$i]['mere'] != ''): ?> M&egrave;re : <?php echo utf8_encode($male[$i]['mere']); ?><br /> <?php endif; if(isset($male[$i]['ligne']) && $male[$i]['ligne'] != ''): ?> Lign&eacute;e : <?php echo utf8_encode($male[$i]['ligne']); ?> <?php endif; ?> </p> <?php endif; endfor; endif; ?> <?php if(isset($femelle)): ?> <p><span class="rub_blue"><?php echo $lang['fr']['nosfemmel']; ?></span></p> <?php for($i=0;$i<4;$i++): // FEMELLE if(isset($femelle[$i]['nom']) && $femelle[$i]['nom'] != ''): ?> <p><span class="rub_black"><?php echo utf8_decode($femelle[$i]['nom']); ?><br /> </span><?php echo utf8_encode($femelle[$i]['desc']); ?><br /> <?php if(isset($femelle[$i]['pere']) && $femelle[$i]['pere'] != ''): ?> P&egrave;re : <?php echo utf8_encode($femelle[$i]['pere']); ?><br /> <?php endif; if(isset($femelle[$i]['mere']) && $femelle[$i]['mere'] != ''): ?> M&egrave;re : <?php echo utf8_encode($femelle[$i]['mere']); ?><br /> <?php endif; if(isset($femelle[$i]['ligne']) && $femelle[$i]['ligne'] != ''): ?> Lign&eacute;e : <?php echo utf8_encode($femelle[$i]['ligne']); ?> <?php endif; ?> </p> <?php endif; endfor; endif; ?> <?php if(isset($chaton)): ?> <p><span class="rub_blue"><?php echo $lang['fr']['noschatons']; ?></span></p> <?php for($i=0;$i<6;$i++): // FEMELLE if(isset($chaton[$i]['nom']) && $chaton[$i]['nom'] != ''): ?> <p><span class="rub_black"><?php echo utf8_encode($chaton[$i]['nom']); ?><br /> </span><?php echo ($chaton[$i]['desc']); ?><br /> <?php if(isset($chaton[$i]['pere']) && $chaton[$i]['pere'] != ''): ?> P&egrave;re : <?php echo utf8_encode($chaton[$i]['pere']); ?><br /> <?php endif; if(isset($chaton[$i]['mere']) && $chaton[$i]['mere'] != ''): ?> M&egrave;re : <?php echo utf8_encode($chaton[$i]['mere']); ?><br /> <?php endif; if(isset($chaton[$i]['ligne']) && $chaton[$i]['ligne'] != ''): ?> Lign&eacute;e : <?php echo utf8_encode($chaton[$i]['ligne']); ?> <?php endif; ?> </p> <?php endif; endfor; endif; ?></td> </tr> <tr> <td valign="top">&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td valign="top" bgcolor="#54ADFF" class="soustitre"><?php echo $lang['fr']['Contact']; ?></td> <td>&nbsp;</td> </tr> <tr> <td valign="top"><p><span class="rub_black"><?php echo utf8_encode($fiche['nomc_chatterie']); ?></span><br /> <?php echo utf8_encode($fiche['adr_chatterie']); ?><br /> <?php if($fiche['adrc_chatterie'] != ''): ?> <?php echo utf8_encode($fiche['adrc_chatterie']); ?><br /> <?php endif; ?> <?php echo $fiche['code_chatterie']; ?> <?php echo utf8_encode($fiche['ville_chatterie']); ?><br /> <br /> <span class="rub_black"><?php echo $fiche['pays_chatterie']; ?></span> <br /> </p></td> <td valign="top"><p> <?php if($fiche['tel_chatterie'] != ''): ?> <strong>T&eacute;l&nbsp;:</strong>&nbsp;<?php echo utf8_encode($fiche['tel_chatterie']); ?><br /> <?php endif; ?> <?php if($fiche['fax_chatterie'] != ''): ?> <strong>Fax&nbsp;:</strong>&nbsp;<?php echo utf8_encode($fiche['fax_chatterie']); ?><br /> <?php endif; ?> <?php if($fiche['mob_chatterie'] != ''): ?> <strong>Mobile&nbsp;:</strong>&nbsp;<?php echo utf8_encode($fiche['mob_chatterie']); ?><br /> <?php endif; ?> <?php if($fiche['cert_chatterie'] != ''): ?> <span class="rub_black">N&deg; de Certificat de Capacit&eacute; :</span> <?php echo utf8_encode($fiche['cert_chatterie']); ?><br /> <?php endif; ?> <?php if($fiche['siret_chatterie'] != ''): ?> <strong>N&deg; de Siret : </strong><?php echo utf8_encode($fiche['siret_chatterie']); ?><br /> <?php endif; ?> <?php if($fiche['url_chatterie'] != ''): ?> <span class="rub_black">Website :</span> <a href="<?php echo $fiche['url_chatterie']; ?>" target="_blank"><?php echo $fiche['url_chatterie']; ?></a></p> <?php endif; ?></td> </tr> <tr> <td valign="top" bgcolor="#54ADFF" class="soustitre">Nous ecrire</td> <td>&nbsp;</td> </tr> <tr> <td colspan="2"><?php if($messageok): ?> <p id="envoiok"><strong style="color:green">Votre message a bien &eacute;t&eacute; envoy&eacute; ! Merci</strong></p> <?php else: ?> <form method="post" action="fiche.php?id=<?php echo $_GET['id']; ?>#envoiok"> <p> <label>Votre adresse email : </label> <input type="text" name="mail" value="" /> </p> <p> <label>Votre message : </label> <textarea name="text"></textarea> </p> <p> <input type="submit" value="Envoyer" name="valid" /> </p> </form> <?php endif; ?></td> </tr> </table> <?php include '_include/foot.php'; ?>

ViPHP
AB
ViPHP | 5818 Messages

27 avr. 2011, 19:59

C'est plus efficace de les redimensionner lors de l'upload car les pages s'afficheront plus vite et cela soulagera le serveur.
Une classe d'upload de fichiers qui peut faire du redimensionnement d'images ici (en plusieurs dimensions si besoin).

Petit nouveau ! | 3 Messages

28 avr. 2011, 07:16

Merci pour la réponse
Voici mon fichier image.class.php comment faire pour avoir des images en 460x352px, car la je suis perdu
Merci

Code : Tout sélectionner

<?php $l_ext = array( 1 => 'gif', 2 => 'jpg', 3 => 'png' ); class Image { private $image; private $source; private $taille; private $qualite; private $data; private $cible; public function Image($image,$qualite=100) { $this->data = @getImageSize($image); $this->source = $image; if($this->isImage()): $this->taille = array($this->data[0], $this->data[1]); $this->qualite=$qualite; $this->cible=false; $this->image=$this->createImage(); endif; } public function isImage() { global $l_ext; return isset($l_ext[$this->data[2]])?true:false; } public function getTaille() { return array($this->data[0],$this->data[1]); } public function getExt() { global $l_ext; return $l_ext[$this->data[2]]; } public function afficherImage() { header('Content-type: '.$this->data['mime']); if($this->cible!=false): header('Content-Disposition: inline; filename="'.$this->cible.'"'); echo file_get_contents($this->cible); else: header('Content-Disposition: inline; filename="'.$this->source.'"'); switch($this->data[2]): case 1: return imagegif($this->image); case 2: return imagejpeg($this->image); case 3: return imagepng($this->image); default: return false; endswitch; endif; } public function sauvegarderImage($file,$chemin="./") { if(!is_dir($chemin)): mkdir($chemin, 0755, true); endif; switch($this->data[2]): case 1: $ext="gif"; imagegif($this->image,$chemin.$file.'.'.$ext); break; case 2: $ext="jpg"; imagejpeg($this->image,$chemin.$file.'.'.$ext); break; case 3: $ext="png"; imagepng($this->image,$chemin.$file.'.'.$ext); break; default: return false; endswitch; $this->cible=$chemin.$file.'.'.$ext; } public function sauvegarderImage2($file) { switch($this->data[2]): case 1: $ext="gif"; @imagegif($this->image,$file); break; case 2: $ext="jpg"; @imagejpeg($this->image,$file); break; case 3: $ext="png"; @imagepng($this->image,$file); break; default: return false; endswitch; $this->cible=$file; } public function transformeImage($mode,$param1="",$param2="",$param3="",$param4="") { switch($mode): case 'gris': $this->grisImage(); break; case 'rotation': $this->rotationImage($param1); break; case 'redimension': $this->redimensionImage($param1,$param2); break; case 'redimension2': $this->redimension2Image($param1,$param2); break; case 'couper': $this->couperImage($param1,$param2,$param3,$param4); break; case 'flip': case 'flop': $this->flipflopImage($mode); break; endswitch; } public function grisImage() { for($c = 0; $c < 256; $c++): $palette[$c] = imageColorAllocate($this->image, $c, $c, $c); endfor; for($x = 0; $x < $this->data[0]; $x++): for($y = 0; $y < $this->data[1]; $y++): $gray = (ImageColorAt($this->image, $x, $y) >> 8) & 0xFF; $rgb = imagecolorat($this->image, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $gs = ($r * 0.299) + ($g * 0.587) + ($b * 0.114); imagesetpixel($this->image, $x, $y, $palette[$gs]); endfor; endfor; } public function rotationImage($degres) { $this->image = imagerotate($this->image, $degres, 0); } function flipflopImage($mode) { $w = $this->data[0]; $h = $this->data[1]; $thumb = imageCreateTrueColor($w, $h); if($mode == 'flip'): for ($x = 0; $x < $w; $x++): imagecopy($thumb, $this->image, $w - $x - 1, 0, $x, 0, 1, $h); endfor; elseif($mode == 'flop'): for($x = 0; $x < $h; $x++): imagecopy($thumb, $this->image, 0, $h - $x - 1, 0, $x, $w, 1); endfor; else: $thumb=$this->image; endif; $this->image=$thumb; } function redimensionImage($width, $height) { if(($this->data[0] == $width) && ($this->data[1] == $height)): return true; endif; $this->taille = array($width, $height); $this->_mainTransform(); } function redimension2Image($width, $height) { if(($this->data[0] == $width) && ($this->data[1] == $height)): return true; endif; list($width2,$height2) = array($this->data[0],$this->data[1]); $this->taille = array($width, $height); $thumb = imageCreateTrueColor($width, $height); imageCopyResampled($thumb,$this->image,0,0,0,0,$width,$height,$width2,$height2); $this->image=$thumb; $this->data[0]=$width; $this->data[1]=$height; } function couperImage($width, $height,$posX,$posY) { if(($this->data[0] == $width) && ($this->data[1] == $height)): return true; endif; $this->taille = array($width, $height); $this->_mainTransform($posX, $posY, $width, $height, false); } function cropSize ($sourceX, $sourceY, $targetX, $targetY) { $sizeX = round(($sourceX * $targetX) / (($sourceX * $targetY) / $sourceY)); $sizeY = $sourceY; $coordX = 0; $coordY = intval(($sourceX / 2) - ($sizeX / 2)); return array($sizeX, $sizeY, $coordX, $coordY); } public function _mainTransform($posX=0, $posY=0, $width=0, $height=0, $proportions=true) { if($proportions): list($dX,$dY) = $this->proportionsImage($this->data[0],$this->data[1]); list($width,$height) = array($this->data[0],$this->data[1]); else: list($dX,$dY) = array($this->taille[0], $this->taille[1]); //list($width,$height) = array($this->data[0],$this->data[1]); endif; list($posX,$posY) = $this->taillemaxImage($posX, $posY, $width, $height); $thumb = imageCreateTrueColor($dX, $dY); imageCopyResampled($thumb,$this->image,0,0,$posX,$posY,$dX,$dY,$width,$height); $this->image=$thumb; $this->data[0]=$dX; $this->data[1]=$dY; } public function proportionsImage($width, $height) { if($width > $height): $n_width = $this->taille[0]; $n_height = round(($n_width * $height) / $width); elseif($height > $width): $n_height = $this->taille[1]; $n_width = round(($n_height * $width) / $height); else: $n_width = $this->taille[0]; $n_height = $this->taille[1]; endif; if($n_width > $this->taille[0]): $n_width = $this->taille[0]; $n_height = round(($n_width * $height) / $width); endif; if($n_height > $this->taille[1]): $n_height = $this->taille[1]; $n_width = round(($n_height * $width) / $height); endif; return array($n_width,$n_height); } public function taillemaxImage($posX, $posY, $width, $height) { $posX = (($posX + $width) > $this->data[0])?($this->data[0] - $width):$posX; $posX = ($posX < 0)?0:$posX; $posY = (($posY + $height) > $this->data[1])?($this->data[1] - $height):$posY; $posY = ($posY < 0)?0:$posY; return array($posX,$posY); } public function createImage() { switch($this->data[2]): case 1: return imageCreateFromGIF($this->source); case 2: return imageCreateFromJPEG($this->source); case 3: return imageCreateFromPNG($this->source); default: return false; endswitch; } public function detruireImage() { imagedestroy($this->image); $this->source=""; $this->taille=array(); $this->data=array(); $this->cible=false; } } ?>

Petit nouveau ! | 3 Messages

02 mai 2011, 23:04

Bonsoir,
un peu d'aide s'il vous plait car ce n'est pas moi qui ai fait le code et je ne comprends pas comment gérer les photos uploadées.
Merci.