Hi,

I need a script to resize JPG, GIF, BMP, TIFF so on. NOT only for JPG please.

I'll be happy if anyone can help me out.

Thanks in advance

Recommended Answers

All 3 Replies

See this

You can use imagecopyresized() to resize an image.
more

just use this. create productimage folder.and create cropimages folder in productimage folder. change crop width,height as your like.

if(is_uploaded_file($_FILES["pimage"]["tmp_name"]))
 {
$img_name=$_FILES["pimage"]["name"];
$randomizer = rand(0000, 9999);
    $file_name = $randomizer.$img_name;
	move_uploaded_file($_FILES["pimage"]["tmp_name"], "productimage/" . $file_name); //set productimage folder  
	
/************************************Resizing the image 128*45****************/
			$path3="productimage";
			$filetype3=$_FILES["pimage"]["type"];
			
			$bgim_file_name = $path3."/".$file_name; 
			$bgimage_attribs = getimagesize($bgim_file_name);
		
			if($filetype3=='image/gif')	
				{
					$bgim_old = imagecreatefromgif($bgim_file_name); 
				}	
			else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))	
				{
					 $bgim_old = imagecreatefromjpeg($bgim_file_name);
				}
			  else	if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
				{
					 $bgim_old = imagecreatefrompng($bgim_file_name);
				}
						
			$bgth_max_width = 128; //for Album image
			$bgth_max_height = 45;
			$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
		
			$bgth_width = 128;//$image_attribs[0] * $ratio; 
			$bgth_height = 45;//$image_attribs[1] * $ratio;
		
			$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
			imageantialias($bgim_new,true); 
			$bgth_file_name = "cropimages/$file_name";
			imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
			if($filetype3=='image/gif')	
				{
				    imagegif($bgim_new,$bgth_file_name,100);
					//$bgim_old = imagegif($bgim_file_name); 
				}	
			else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))	
				{
					 imagejpeg($bgim_new,$bgth_file_name,100);
				}
			  else	if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
				{
					 imagepng($bgim_new,$bgth_file_name,100);
				}				
			/************End Resize of 128*45*******************/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.