Resized proportionately more images

Hello everyone
In fact, I have my script to resize an image proportionally works well and register myself with the image a name entered in a

text box on a

directory.

What I want changed is the ability to resize the same image three times (with the name entered in the textbox, and stored on the

server.
Thank you any indication which may help me to complete my script

<!------------------------------ page index.php------------------------------------>

<html>
<head></head>
<body>
<!–On affiche le formulaire d’envoi d’une image–>
<center>
<br /><hr />

&lt;form method="post" enctype="multipart/form-data" action="upload.php"&gt;
&lt;p&gt;



   Le nom de l'image redimensionner avec 171 ,107
   &lt;input type="text" name="video"&gt;&lt;br&gt;&lt;br&gt;
   
   
   
   Le nom de l'image redimensionner avec 200 ,200 
   &lt;input type="text" name="video2"&gt;&lt;br&gt;&lt;br&gt;
   
   
   Le nom de l'image redimensionner avec 500 ,500 
   &lt;input type="text" name="video3"&gt;&lt;br&gt;&lt;br&gt;
   
&lt;input type="file" name="fichier" size="30"&gt;
&lt;input type="submit" name="upload" value="Uploader"&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/center&gt;

</body>
</html>

<!------------------------------ fin page index.php------------------------------------>

<!------------------------------ page upload.php------------------------------------>

<?php

$nomImage=$_POST[‘video’];

if( isset($_POST[‘upload’]) ) // si formulaire soumis
{
$content_dir = ‘upload/’; // dossier où

sera déplacé le fichier

$tmp_file = $_FILES['fichier']['tmp_name'];

if( !is_uploaded_file($tmp_file) )
{
    exit

(“Le fichier est introuvable”);
}

// on vérifie maintenant l'extension
$type_file = $_FILES['fichier']['type'];

if( 

!strstr($type_file, ‘jpg’) && !strstr($type_file, ‘jpeg’) && !strstr($type_file, ‘png’) && !
strstr($type_file, ‘bmp’) && !strstr($type_file, ‘gif’) )
{
exit(“Le fichier n’est pas une image”);
}

// on 

copie le fichier dans le dossier de destination

$ext = substr($_FILES['fichier']['name'], strrpos($_FILES['fichier']

[‘name’], ‘.’));

$name_file = $nomImage.$ext;
echo $name_file;


//fonction pour changer les dimentions des 

fichiers
function redimensionner($file, $maxwidth, $maxheight) {
/*
$maxwidth = 171;
$maxheight = 171;
*/
list($rawwidth,

$rawheight, $type) = @getimagesize($file);

if ($maxwidth < $rawwidth && $rawwidth >= $rawheight) {

$width = $maxwidth;

$height = ($width / $rawwidth) * $rawheight;

}

elseif ($maxheight < $rawheight && $rawheight >= $rawwidth) {

$height = 

$maxheight;

$width = ($height /$rawheight) * $rawwidth;

}

else {

$height = $rawheight;

$width = $rawwidth;

}

$imgbuffer = imagecreatetruecolor($width, $height);

switch($type) {

case 1: $image = imagecreatefromgif($file); break;

case 2: $image = imagecreatefromjpeg($file); break;

case 3: $image = imagecreatefrompng($file); break;

case 4: $image = 

imagecreatefrombmp($file); break;

default: exit("Tried to create thumbnail from $file: not a valid image");

}

if (!$image)

exit(“Image creation from $file failed for an unknown reason. Probably not a valid image.”);

else {

imagecopyresampled

($imgbuffer, $image, 0, 0, 0, 0, $width, $height, $rawwidth, $rawheight);

imageinterlace($imgbuffer);

switch($type) {




  case 1: $image = imagegif($imgbuffer, $file, 80); break;

  case 2: $image = imagejpeg($imgbuffer, $file, 80); 

break;

  case 3: $image = imagepng($imgbuffer, $file, 7); break;



}

}

}

if( preg_match(‘#[\x00-\x1F\x7F-\x9F/\\\\]#’,

$name_file) )

{

exit(“Nom de fichier non valide”);

}

else if( !move_uploaded_file($tmp_file, $content_dir . $name_file) )

{

exit(“Impossible de copier le fichier dans $content_dir”);

}

redimensionner($content_dir.$name_file, 171, 107);

}
?>

<!------------------------------ fin page upload------------------------------------>
------------------>

I already tried to do as thee say, but I can not
you can give more detailed stp

Hello
In fact, I wanted to load images with different sizes in the same folder “upload”.
One more piece of code that you gave me does not traitor names that I type in text boxes for each image.
I ask if possible more explanation
Thank you

Hello everyone,
I have a script to resize the image proportionately, it takes the largest value (height or width), and the other value scales proportionally.
The only problem with this script is that it does not set max height and max.

For example, I wanted to generate an image with: max width: 171 and max height: 107
If I take a picture with the denials width: 420, height 298, the proportional resizing cava give:
420>> 298
171>> x
x = (298 * 171) / 420 = 121 (larger than I wanted for a max height 107).
J’image what to do, but I do not know how to run it for a loop:
H>> W
171>> 121 (top of my max, I do not), I H - 1
170>> 120 (top of my max, I do not) I’m making a H-1



150>> 107 (<= 107, I take it)
What is important for me is to respect the power proportional resizing does not distort the image, and at the same time does not exceed the max denied.
I’m listening to your comments.
Thank you in advance



<!-------------------------------index.php  -------------------------------------->
<html>
<head></head>
<body>
	<!--On affiche le formulaire d'envoi d'une image-->
	<center>
	<br /><hr />

	<form method="post" enctype="multipart/form-data" action="upload.php">
	<p>
	
	
	
	   Le nom de l'image redimensionner avec 95 ,95
	   <input type="text" name="video"><br><br>
	   
	  
	   
	<input type="file" name="fichier" size="30">
	<input type="submit" name="upload" value="Uploader">
	</p>
	</form>
	</center>
	
  </body>
  </html>
<!-----------------------------------  ------------------------------------------->


<!------------------------------- upload.php -------------------------------------->
<?php


$nomImage=$_POST['video'];

if( isset($_POST['upload']) ) // si formulaire soumis
{
    $content_dir = 'upload/'; // dossier où 

sera déplacé le fichier

    $tmp_file = $_FILES['fichier']['tmp_name'];

    if( !is_uploaded_file($tmp_file) )
    {
        exit("Le 

fichier est introuvable");
    }

    // on vérifie maintenant l'extension
    $type_file = $_FILES['fichier']['type'];

    if( !

strstr($type_file, 'jpg') && !strstr($type_file, 'jpeg') && !strstr($type_file, 'png') && !strstr($type_file, 'bmp') && !strstr

($type_file, 'gif') )
    {
        exit("Le fichier n'est pas une image");
    }

    // on copie le fichier dans le dossier de 

destination
	
	$ext = substr($_FILES['fichier']['name'], strrpos($_FILES['fichier']['name'], '.'));

	$name_file = 

$nomImage.$ext;
	echo $name_file;


	//fonction pour changer les dimentions des fichiers
  function redimensionner($file, 

$maxwidth, $maxheight) {

list($rawwidth, $rawheight, $type) = @getimagesize($file);

  if ($maxwidth < $rawwidth && $rawwidth >= 

$rawheight) {

    $width = $maxwidth;

    $height = ($width / $rawwidth) * $rawheight;

  }

  elseif ($maxheight < $rawheight && 

$rawheight >= $rawwidth) {

    $height = $maxheight;

    $width = ($height /$rawheight) * $rawwidth;

  }

  else {

    $height = 

$rawheight;

    $width = $rawwidth;

  }

  $imgbuffer = imagecreatetruecolor($width, $height);

  switch($type) {

    case 1: $image = 

imagecreatefromgif($file); break;

    case 2: $image = imagecreatefromjpeg($file); break;

    case 3: $image = imagecreatefrompng

($file); break;

    case 4: $image = imagecreatefrombmp($file); break;

    default: exit("Tried to create thumbnail from $file: not 

a valid image");

  }

  if (!$image) exit("Image creation from $file failed for an unknown reason. Probably not a valid image.");

  

else {

    imagecopyresampled($imgbuffer, $image, 0, 0, 0, 0, $width, $height, $rawwidth, $rawheight);

    imageinterlace

($imgbuffer);

    switch($type) {

	
	
	
      case 1: $image = imagegif($imgbuffer, $file, 80); break;

      case 

2: $image = imagejpeg($imgbuffer, $file, 80); break;

      case 3: $image = imagepng($imgbuffer, $file, 7); break;

  

    }

  }

}


if( 

preg_match('#[\\x00-\\x1F\\x7F-\\x9F/\\\\\\\\]#', $name_file) )

{

  exit("Nom de fichier non valide");

}

  else if( !move_uploaded_file

($tmp_file, $content_dir . $name_file) )

{

  exit("Impossible de copier le fichier dans $content_dir");

} 

redimensionner

($content_dir.$name_file,171, 107);

}
?>

<!-----------------------------------  ------------------------------------------->

Basicly you need to repeat your function three times with differnt values for $content_dir other wise they will overwrite each other:


$content_dir = 'Large/';
redimensionner($content_dir.$name_file, 371, 307);
$content_dir = 'medium/';
redimensionner($content_dir.$name_file, 271, 207);
$content_dir = 'small/';
redimensionner($content_dir.$name_file, 171, 107);

It would be simpler if you used ImageMagick :wink:

P.S. Put your code between [ php ] [ /php ] without the spaces on the forum. You can use the icon at the top of the post box that looks like a page with php on it.

turn it into a class or function and run a loop 3 times.

proportion of images and content has to be there in a stable manner,but many a times due to the coding error excecution does not take place