Fork me on GitHub






imageresizer - Redimensionner en pixels et non en %
Régulier
Inscrit: 23/06/2004 17:28
Messages: 311
Salut tous, je suis en galère et j'espère obtenir un coup de pouce afin de solutionner mon soucis :

Catads ne permettant pas de redimensionner les images,je souhaiterais utiliser le module "imageresizer" afin de permettre à mes membres de redimensionner leurs photos avant publication.

mon pb est que ce module propose de redimensionner l'image à x% de la taille originale.

Je souhaiterais pour ma part redimensionner systématiquement à 700 pixels de large et je n'arrive pas à convenablement modifier le code, je suis vraiment un quichon...

Si l'un d'entre vous pouvait m'indiquer les modifs à réaliser, cela me retirerait une grosse épine du pied car je n'arrive à rien!ça semble pourtant facile... mais à chaque essai, c'est infructueux


Merci

voilà le code original :

<?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">Choose image for resize: <input type="file" name="image"><br /><br>
Percent of resize: <input type="text" name="percent" maxlenght="2" size="2" value="50"> % of original image.<br /><br>
<input type="submit" value="GO!"><br>
</form>

<?php

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

$percent=$_POST['percent'];
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 
"Only jpeg, png and gif images are allowed.";
    }
    else
    {
$target_path "resizedimages/" basename$_FILES['image']['name']);

if(
move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
    echo 
"";
} else{
    echo 
"The image could not have been resized!";
}

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

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

  echo 
"Original Image: $file, has width: $width and height $height";

$percent=$percent/100;

$new_widthround($percent*$width);
$new_heightround($percent*$height);

 
$filename="resizedimages/$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"resizedimages/resized_$file);

echo 
"<br /><img src="resizedimages/resized_$file"><br />Resized image, has width: $new_width and height $new_height <br /> To save image: Right click on image and save as.";
    }

}
?>
<br />
<!-- Please do not delete the link to this useful tool. Instead, let every site have it! After all, it's free, and i'm sure you're happy you found it... -->
<br><br><a target="blank" href="http://www.selges.org">Online Image Resizer</a>
<br>

</div></font>

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

?>

Posté le : 27/08/2009 16:50
Partager Twitter Partagez cette article sur GG+
Re: imageresizer - Redimensionner en pixels et non en %
Régulier
Inscrit: 23/06/2004 17:28
Messages: 311
Je vous poste ma modif (de codeur du dimanche :roll:) :

<?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">Choose image for resize: <input type="file" name="image"><br /><br>
xsize of resize: <input type="text" name="xsize" maxlenght="2" size="2" value="700"> % of original image.<br /><br>
<input type="submit" value="GO!"><br>
</form>

<?php

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

$xsize=$_POST['xsize'];
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 
"Only jpeg, png and gif images are allowed.";
    }
    else
    {
$target_path "resizedimages/" basename$_FILES['image']['name']);

if(
move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
    echo 
"";
} else{
    echo 
"The image could not have been resized!";
}

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

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

  echo 
"Original Image: $file, has width: $width and height $height";

$xsize=$xsize/100;

$new_widthround($xsize*$width);
$new_heightround($ysize*$height);

 
$filename="resizedimages/$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"resizedimages/resized_$file);

echo 
"<br /><img src="resizedimages/resized_$file"><br />Resized image, has width: $new_width and height $new_height <br /> To save image: Right click on image and save as.";
    }

}
?>
<br />
<!-- Please do not delete the link to this useful tool. Instead, let every site have it! After all, it's free, and i'm sure you're happy you found it... -->
<br><br><a target="blank" href="http://www.selges.org">Online Image Resizer</a>
<br>

</div></font>

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

?>


Alors... ça fonctionne, mais la ressource consommée est énorme, donc... pas envisageable!

Vous avez une soluce ???

Posté le : 27/08/2009 17:31
Partager Twitter Partagez cette article sur GG+
Re: imageresizer - Redimensionner en pixels et non en %
Régulier
Inscrit: 23/06/2004 17:28
Messages: 311
Idéalement, il faudrait intégrer la fonction de redimensionnement inclus par exemple dans extgallery au module catads. Mais ça semble relativement peu facile.

Personne n'a tenté de plancher là dessus non plus?

Posté le : 28/08/2009 11:08
Partager Twitter Partagez cette article sur GG+

 Haut   Précédent   Suivant



Vous pouvez voir les sujets.
Vous ne pouvez pas débuter de nouveaux sujets.
Vous ne pouvez pas répondre aux contributions.
Vous ne pouvez pas éditer vos contributions.
Vous ne pouvez pas effacez vos contributions.
Vous ne pouvez pas ajouter de nouveaux sondages.
Vous ne pouvez pas voter en sondage.
Vous ne pouvez pas attacher des fichiers à vos contributions.
Vous ne pouvez pas poster sans approbation.

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

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