Jump to content

PNG Files help


spires

Recommended Posts

Hi Guys

 

I'm working on a image upload and resize script.

So far I can upload jpg files, resize them and place the resized jpg file into a thumbnails folder.

 

However, if I try to upload a PNG file, the image uploads but wont resize.

 

Can anyone help?

 

Example:

http://reviews4mobilephones.com/test.php

 

 

Code:

<?PHP


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

if ($_FILES['image']['name']==''){

}else{

 $random_digit=rand(00000000,99999999);
 $width = 200; // size of width


     $filedir = 'images/test/orig/'; // the directory for the original image 
     $thumbdir = 'images/test/thumb/'; // the directory for the thumbnail image 
    $largedir = 'images/test/large/'; // the directory for the large image 
     $prefix = ''; // the prefix to be added to the original name 

     $maxfile = '1000000'; // max file size
     $mode = octdec('0666'); // octdec -- Octal to decimal.
 						// The mode parameter consists of three octal number components specifying access restrictions for the owner,
						// the user group in which the owner is in, and to everybody else in this order. e.g (666)
      
     $userfile_name = $_FILES['image']['name']; 
     $userfile_tmp = $_FILES['image']['tmp_name']; 
     $userfile_size = $_FILES['image']['size']; 
     $userfile_type = $_FILES['image']['type'];
    $userfile_error = $_FILES['image']['error'];


     $imgsize = @getimagesize($userfile_tmp); // sticks in the image size into the array ($imgsize)
     $origwidth = $imgsize[0]; // = image width
     $origheight = $imgsize[1]; // = image height
     $ratio = ($origheight/$origwidth); //
     $height = ($width * $ratio);   

 	$flag = 0;
 if(strcmp($userfile_type, "image/jpeg")==0){
	 $type='jpg'; 
	 $flag = 1;
	}elseif (strcmp($userfile_type, "image/pjpeg")==0){
	 $type='jpg'; 
	 $flag = 1;
}
 if(strcmp($userfile_type, "application/x-shockwave-flash")==0){
	 $new_img_name = $random_digit.".swf"; 
	  $type='swf'; 
	 $flag = 2;
	}
 if(strcmp($userfile_type, "image/gif")==0){
	 $new_img_name = $random_digit.".gif";
	  $type='gif'; 
	 $flag = 3;
	}
 if(strcmp($userfile_type, "image/png")==0){
	 $type='png'; 
	 $flag = 4;
	}

	$new_img_name = $random_digit.'.'.$type;

	if($type == 0){
 	$wrong_type = "<span class='pro_guide_text'>wrong file type.<br>  You can upload .jpg, .png, .gif and .swf files only.</span>";
	}



 	// $prod_img = the image folder and the image and name
         $prod_img = $filedir.$new_img_name; 
								$prod_img_thumb = $thumbdir.$new_img_name; 

	 //move_uploaded_file -- Moves an uploaded file to a new location.
	 //move the uploaded file to the image folder with a tempory name.
         if(move_uploaded_file($userfile_tmp, $prod_img)){
        $moved =  "Thank You, Your File Has Been Uploaded";
         }
         else{
        $moved =  "Sorry, Your File Failed To Upload";
         }

     
				echo $prod_img;

	 // chmod -- Changes file mode, 
	 // set the user interface for the image
         chmod ($prod_img, $mode); 
         // getimagesize -- Get the size of an image
	 // find the size of the original image
         $sizes = getimagesize($prod_img); 


			 $new_height = $height; 
			 $new_width = $width;
		   //  $new_width = abs($new_height/$aspect_ratio); 
			// this code will only change the height, and make the width in ratio


         $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); 
								$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); 



         ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); 

	  
			     ImageCopyResampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $sizes[0], $sizes[1]) or die('Problem In resampling');
    
			     ImageJPEG($destimg, $prod_img_thumb,90) or die('Problem In saving'); 

         imagedestroy($destimg);
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>

<body>


<form action="<?PHP $_SERVER['PHP_SELF']; ?>" method="post" name="form1" enctype="multipart/form-data">

<table width="480" border="0" cellspacing="1" cellpadding="0">

<tr>
<td colspan="4"><br>Image: 
<input type="file" name="image"></td>
</tr>
<tr>
<td colspan="4" height="30">
<input name="submit" type="submit" value="submit" />
</td>
</tr>
</table>
</form>
<?PHP
/*
echo '
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="491" height="73">
  <param name="movie" value="images/test/orig/53959737.swf">
  <param name="quality" value="high">
  <embed src="images/test/orig/53959737.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="491" height="73"></embed>
</object><br><br>*/



?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/122881-png-files-help/
Share on other sites

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.