Jump to content

[solved] Php Resize & Upload Image


morrisjohnny

Recommended Posts

If there aren't any errors it doesn't sound like there's a problem - if there was an error saving the file or whatever you should see that on the page. You can just add echo statements so that you can see what resize image is doing (or not doing):

function resize_image($opts){  $src = isset($opts['source']) ? $opts['source'] : '';  $dest = isset($opts['dest']) ? $opts['dest'] : '';  $w = isset($opts['w']) ? intval($opts['w']) : 0;  $h = isset($opts['h']) ? intval($opts['h']) : 0;    if ($src == '')  {	echo 'no source';	return false;  }  if ($w == 0 && $h == 0)  {	echo 'no dimensions';	return false;  }  if ($dest == '')  {	echo 'overwrite original;';	$dest = $src; // resize in place  }  // open the image  $ext = strtolower(array_pop(explode('.', $src)));  switch ($ext)  {	case 'jpg':	case 'jpeg':	  $i = imagecreatefromjpeg($src);	break;	case 'gif':	  $i = imagecreatefromgif($src);	break;	case 'png':	  $i = imagecreatefrompng($src);	break;	default:	  echo 'extension not found';	  return false;  }  $new_w = imagesx($i);  $new_h = imagesy($i);  echo 'width:' . $new_w . ';height:' . $new_h . ';';  if (($w != 0 && $new_w < $w && $h == 0) ||	  ($w == 0 && $h != 0 && $new_h < $h) ||	  ($w != 0 && $new_w < $w && $h != 0 && $new_h < $h))  {	echo 'image does not need to be resized';	// image is small enough	if ($dest != $src)	{	  copy($src, $dest);	  chmod($dest, 0644);	}	return true;  }  // determine new size  if ($w != 0 && $new_w > $w)  {	$new_h = ($w / $new_w) * $new_h;	$new_w = $w;  }  if ($h != 0 && $new_h > $h)  {	$new_w = ($h / $new_h) * $new_w;	$new_h = $h;  }  echo 'new width:' . $new_w . ';new height:' . $new_h . ';';  // resize  $new = imagecreatetruecolor($new_w, $new_h);  imagecopyresampled($new, $i, 0, 0, 0, 0, $new_w, $new_h, imagesx($i), imagesy($i));  imagedestroy($i);  echo 'saving ' . $dest . ';';  // save the image  switch ($ext)  {	case 'jpg':	case 'jpeg':	  echo 'save jpeg;';	  imagejpeg($new, $dest);	break;	case 'gif':	  echo 'save gif;';	  imagegif($new, $dest);	break;	case 'png':	  echo 'save png;';	  imagepng($new, $dest);	break;  }  chmod($dest, 0644);  imagedestroy($new);  echo 'done';  return true;}

Link to comment
Share on other sites

I appriate your help JustSomeGuy. Here's the new messages:overwrite original;extension not foundoverwrite original;extension not foundnow working backwards from the errors it says image not found, because of the file extention is that because it's getting renamed .img and it's not passing the jpg/gif/ png test correct? now i looked at the imagecreatefrom... function but obioulsy theirs not one for .img as img isn't a file extentsion. so we must continue to save the file as the correct file extention or is their a way to detect the orginal file extention? to overwrite the file? (The errors are echoing twice as theirs two image files.

Link to comment
Share on other sites

Editokay i added this little script

$number=0;$img2=explode(".", $_FILES["imagefile2"]["name"]);while(isset($img2[$number])){	$img2ext='.'.$img2[1];	echo $img2ext."<br />".$number."<br />";	$number++;}.....'dest_fname' => 'latest2'.$img2ext,

And the file worksi know the code is scruffy, just about to tip it up. i want to say a big thank you JustSomeGuy. for all your support on this matter. i'm not going to exmine my whole code to use as a learning Guide.Thank you soo muchUn EditOkay when i tried to replace the dest_fname from 'dest_fname' => 'latest.img', // optionalto this 'dest_fname' => 'latest'.(strtolower(array_pop(explode(".", $_FILES[$input]["name"])))),Which i would have though would echo the filename i recieve the error.Notice: Undefined variable: input in C:\My Software\Xampp\htdocs\Business\AJS Clothing\WIP\admin.php on line 296Notice: Undefined index: in C:\My Software\Xampp\htdocs\Business\AJS Clothing\WIP\admin.php on line 296overwrite original;extension not found

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...