Page 1 of 1

Not always resizing?

Posted: Mon Apr 30, 2007 6:49 pm
by psychotomus
how come my code doesn't resize all images 100% of the time?

Code: Select all

if ($file_type == "jpg")
		{
			if (move_uploaded_file($_FILES["file"]["tmp_name"], "screens/" . $filename))
			{
				if(!$src = imagecreatefromjpeg("screens/" .$filename))
				{
					echo 'error creating image';
				}
				else
				{
					$w = imagesx($src); 
					$h = imagesy($src);
					
					if ($w > 350 || $h > 250)
					{
						
						// Create thumbnail canvas 
						$destimg = imagecreatetruecolor ("350", "250") or die ("Problem In Creating image"); 
				
						// For JPEG 
						$srcimg = imagecreatefromjpeg ("screens/" . $filename) or die ("Problem In opening Source Image");  
						
						// Resample the image from $srcimg to the $destimg
						imagecopyresampled ($destimg, $srcimg, 0, 0, 0, 0, "350", "250", imagesx($srcimg), imagesy($srcimg)) or die ("Problem In resizing");   
						
						// Save JPG 
						imagejpeg ($destimg, "screens/" . $filename) or die("Problem In saving");  
					}
				}
			}
			else
			{
				$eRR = "Could not upload file";
			}
		}

Posted: Mon Apr 30, 2007 6:58 pm
by John Cartwright
Let me just say, were not here to debug your scripts for you. Don't take our precious time and effort around here for granted. At minimum, you should post what you've attempted to solve the solution, such as any debuging information.

What kind of images were you trying to upload? Size of image? Error messages? Anything is better than nothing.

To answer your question with the same effort your given us, likely because your if statements are failing. :wink:

Posted: Tue May 01, 2007 2:58 am
by onion2k
You have a condition that makes it only resize an image if the width is greater than 350 or the height is greater than 250.

Code: Select all

if ($w > 350 || $h > 250)
You really ought to rewrite the resizing code anyway. It's ignoring the aspect ratio when it generates the smaller image which is going to make the thumbnails look really nasty.