Fork me on GitHub

Rapport de message :*
 

Re: Redimensionner des photos

Titre du sujet : Re: Redimensionner des photos
par RC78 sur 03/05/2009 16:46:15

J'ai bien résolu le problème mais le soucis est que la requête est bien trop grosse et cela fait ralentir le serveur
Il suffit de donner une largeur de photo en pixels et le calcul de la hauteur est automatique suivant les proportions d'origine

Je vous communique le bout de script

@+ Titi

<?php
include("../../mainfile.php");
include(
XOOPS_ROOT_PATH."/header.php");
$xoopsOption['show_rblock'] = 1;
?>

<div align="center"><bgcolor="#800000">
<img border="0" src="imageresizer_banner.jpg" width="" height=""><br><br></div>

<div align= "center">
<form  enctype="multipart/form-data" action="index.php" method="post" name="news">
<input type="hidden" name="img" value="image">
<font face="Verdana" size="2">

   <table width="600" border="0" cellspacing="0" cellpadding="0">
   <tr>
       <td>
           <br/><strong>Utilitaire pour redimensionn&eacute;e vos photos</strong><br/></strong>
           Vous pouvez red&eacute;finir la largeur de la photo mais de base elle est r&eacute;gler &agrave; 700 pixels.<br/>
      La photo sera redimensionn&eacute;e avec un calcul ratio.<br/><br/>
      Attention: Poids maximum de la photo &agrave; redimensionn&eacute;e : 6 MO.<br/>
      </td>
   </tr>
   </table>    

<!-- Image -->
   <table width="450" border="0" cellspacing="0" cellpadding="0">
   <tr>
   <td>Image : 
   <input type="file" name="image" size="30"></td>
   </tr>
   </table>
<!-- end file Image -->

<!-- width xsize largeur de la photo -->
   <table width="450" border="0" cellspacing="0" cellpadding="0">
   <tr>
   <td>Largeur :
   <input name="xsize" type="text" size="4" maxlength="4" value="700" /> pixels.</td>
   </tr>
   </table>
<!-- end file width xsize largeur de la photo -->

<!-- start okay button table -->
   <table width="450" border="0" cellspacing="0" cellpadding="0">
   <tr>
   <td><input name="submitbutton" type="submit" value="Valider" /></td>
   </tr>
   </table>
<!-- end okay button table -->

</form>

<?php

if(isset($_POST['img'])) {

$xsize=$_POST['xsize'];
$ysize=$_POST['ysize'];
if (
$_FILES['image']['size']> 4194304)
{
echo 
"Your image should be smaller than 4 megabytes";
}
    if (!(
$_FILES['image']['type'] =="image/jpeg" OR $_FILES['image']['type']=="image/png" OR $_FILES['image']['type']=="image/gif"))
    {
    echo 
"L&#39;image n'est pas dans un format reconnu. Extensions autoris&eacute;es : jpg/jpeg, gif, png";
    }
    else
    {
$target_path "photoresize/" basename$_FILES['image']['name']);

if(
move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
    echo 
"";
} else{
    echo 
"L&#39;image n'est pas dans un format reconnu. Extensions autoris&eacute;es : jpg/jpeg, gif, png";
}

    
    
$file      basename$_FILES['image']['name']);
    
$file_info getimagesize("photoresize/" $file);

  
$width $file_info[0] ;
  
$height $file_info[1];

  echo 
"Origine de la photo: $file - largeur:  $width pixels - hauteur: $height pixels";

    
// Taille de votre image
  
$new_widthround($xsize);
    
    
// Contraint le rééchantillonage à une largeur fixe et maintient le ratio de l'image
    
$new_height round(($new_width $width) * $height);

 
$filename="photoresize/$file";
    if(
$_FILES['image']['type']=="image/jpeg"){ $img imagecreatefromjpeg($filename);}
    elseif(
$_FILES['image']['type']=="image/gif"){ $img imagecreatefromgif($filename);}
    elseif(
$_FILES['image']['type']=="image/png") { $img imagecreatefrompng($filename);}
       
     
$tmp_img imagecreatetruecolor$new_width$new_height );

      
// copy and resize old image into new image
      
imagecopyresized$tmp_img$img0000$new_width$new_height$width$height );
    


      
// save thumbnail into a file
      
imagejpeg$tmp_img"photoresize/thumb_$file);

echo 
"<br /><img src="photoresize/thumb_$file"><br />Dimension de la photo - Largeur : $new_width pixels - Hauteur $new_height pixels <br /> Pour sauvegarder : R&eacute;aliser un Clic droit avec votre souris sur la photo et Enregistrer l&#39;image Sous.";
    }

}
?>
<br />

</div></font>

<?php
include(XOOPS_ROOT_PATH."/footer.php");

?>

Propulsé avec XOOPS | Graphisme adapté par Tatane, Grosdunord, Montuy337513

34 Personne(s) en ligne (25 Personne(s) connectée(s) sur Forum) | Utilisateur(s): 0 | Invité(s): 34 | Plus ...