Jump to content


Photo

Resizing original image?


  • Please log in to reply
4 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 05 September 2006 - 08:45 PM

Hi,

Does anyone know if its posiable to resize the original image as well as creating a thumb nail.

At the moment i can create thumbnails. but the original image stays the same.
I need to find a way of setting the original image to a fixed size.

I want the user to be able to click a thumbnail image, which will display the origanal image.
I can do this, but if the user loads a big image it makes the screen look messy.
So i would like the original to be fixed at 600px wide.

Heres my code
<?php
$sql_select = "SELECT * FROM user_info WHERE username='$un'";
$query_select = mysql_query($sql_select) or die ('Could not connect');
$row_select= mysql_fetch_array($query_select);
$id = $row_select['id'];
if(isset($_POST['banner_submit'])) 

{ 
     $size = 74; // the thumbnail height 
	 $width = 450; // size of width


     $filedir = 'original/'; // the directory for the original image 
     $thumbdir = 'banner/'; // the directory for the thumbnail image 
	 $largedir = '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'];
	 $file_ext = substr($_FILES['ufile']['name'], strrpos($_FILES['ufile']['name'], '.')+1); 
      
	  // if you have a the image and name then carry on
     if (isset($_FILES['image']['name']))  { 
	 
	 $new_file_name = $id.$userfile_name;
	 
	 	// $prod_img = the image folder and the image and name
         $prod_img = $filedir.$new_file_name; 
		
		// $prod_img_thumb = the thumb folder, the prefix (if you want it) and the image and name
         $prod_img_thumb = $thumbdir.$prefix.$new_file_name; 
		 
		 //move_uploaded_file -- Moves an uploaded file to a new location.
		 //move the uploaded file to the image folder with a tempory name.
         move_uploaded_file($userfile_tmp, $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); 
		 
         $aspect_ratio = $sizes[1]/$sizes[0]; 
		// if its less than the size you want it, dont change
			 if ($sizes[1] <= $size) { 
				 $new_width = $sizes[0]; 
				 $new_height = $sizes[1]; 
			// else, change image size
			 }else{ 
				 $new_height = $size; 
				 $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); 
		}			
	 $date = date("Y-m-d > H:i:s");
	 $url = $_POST['url'];
	 
	 
	 $sql = mysql_query("INSERT INTO banner (id, new_file_name, date, url) VALUES ('$id', '$new_file_name', '$date', '$url')");
	 $sql_price = mysql_query("INSERT INTO banner_account (ban_id, price) VALUES ('$id', 25)");		
		if ($sql) {
		 $uploaded = 'Files Uploaded'; 
		 }else{
		 $notuploaded = 'Your file did not upload';
		 }

	
} 

Thanks for any help
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 05 September 2006 - 09:04 PM

Also resize your original to the new size with a width=600 and remember that you also have to resize the new heigth proportional to the original size.

Or, if you don't want that, specify your new height and width in the HTML <img...> statement.

Ronald  8)

RTFM is an almost extinct art form, it should be subsidized.

#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 05 September 2006 - 09:11 PM

Thanks.

but is there some of your message missing?

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 05 September 2006 - 09:15 PM

No, the reply starting word 'Also' should not be there.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#5 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 05 September 2006 - 09:22 PM

ok, thanks for the reply,

i'll go try it out.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users