Jump to content

resizing multiple images


eZe616

Recommended Posts

I have a form to upload multiple images at once, that works good. It's when I put in the resize function that it won't work. for some reason, it only does it for 1 image. every other get's an error msg

 

here the script. can anybody something wrong with it?

function resize($img)
{
	$src = imagecreatefromjpeg($img);
	$width = imagesx($src);
	$height= imagesy($src);
	$x = 600;
	$y = ($height/$width) * 600;
	$dst = imagecreatetruecolor($x,$y);
	imagecopyresampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
	$file = "upload/$img";
	imagejpeg($dst,$file);

	return $file;
}


foreach ( $_FILES["pictures"]["error"] as $key => $error ) 
	{
		if ( $error == UPLOAD_ERR_OK ) 
			{

				 $tmp_name = $_FILES["pictures"]["tmp_name"][$key];					
       				 $name = $_FILES["pictures"]["name"][$key];
				 $path = "upload/$name";



        			 if( is_uploaded_file($tmp_name))
				 	{
						list($width,$height) = getimagesize($tmp_name);
						$resize = resize($name);

						echo "<img src=\"".$resize."\"><br /><br />";

					}


		}
	}

Link to comment
https://forums.phpfreaks.com/topic/52972-resizing-multiple-images/
Share on other sites

These are the errors I'm getting...it's for every image I upload.If I upload 4 images, i'll get it 4 tmes

 

 

Warning: imagecreatefromjpeg(IMG_2646.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 80

 

Warning: imagesx(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 81

 

Warning: imagesy(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 82

 

Warning: Division by zero in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 84

 

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 85

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 86

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\res\imgupl.php on line 88

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.