Current location: Hot Scripts Forums » Programming Languages » PHP » Help with image resize


Help with image resize

Reply
  #1 (permalink)  
Old 02-23-04, 06:03 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Help with image resize

I'm lost in trying to add a resize function into this upload script. This is for a personal website, and most of the pictures added are throwing the display page way out of whack. I want them to display at a maximum of 500px wide or 500px high. Any help on this one?

PHP Code:

$file_types = array(   
     
'image/pjpeg' => 'jpg'
     
'image/jpeg' => 'jpg'
    ); 
     
$fname=$_POST['fname']; 
     
$title=$_POST['title'];
     
$desc=$_POST['desc'];
    
    
     
$max_size 1024000;
     
$filesize $_FILES['upfile']['size'];
     
$filetype $_FILES['upfile']['type'];
     
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "/Hall/pics/"
       if((!
$fname) || (!$title) || (!$desc)){
 echo 
'You did not submit the following required information. Use your browsers "back" button to complete your form. <br />';
 if(!
$fname){
  echo 
"Name is a required field. <br />";
 }
 if(!
$title){
  echo 
"Photo title is a  required field. <br />";
 
 }
              if(!
$desc){
  echo 
"Photo description is a  required field. <br />";
 
 }
               }else{
       
        if (
$filesize $max_size){
           
header ("location: size_error.php");
           exit;
        }
         if (!
array_key_exists($filetype$file_types)) { 
                
header ("location: type_error.php"); 
            exit;
        } 
        else
        {   
                
$new_file substr(sha1(rand(10time())), 08) . '.' $file_types[$filetype]; 
               if (
move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_dir $new_file)) { 
                 
              
$filename=$new_file;
               
                
              include(
"connect.php");
              
$conn mysql_connect(localhost,"$dbuser","$dbpass") or die ("Could not connect to MySQL"); 
              
mysql_select_db("$db") or die ("Could not open database"); 
              
$query "INSERT INTO fpc_items VALUES('','$fname','$title','$desc','$filename',now(),'')"
              
$result=mysql_query($query); 
      }
   }
mysql_close(); 
header ('Location: upload_success.php');

Thnx....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-23-04, 05:13 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
An idea ?

I have no real idea how to do this but I am doing something simular using "ezresults " and I use "<a href=display.php?picture=COL3&height=200 >" which when the thumbnail is selected it goes to the next page calling up the name of the picture and resizes it.

Or could you use something simular to what NeverMind showed me "include_once('somefolder/' . $ref . '.inc');" and change "('somefolder/'.$ref.'height=500')" ?

Probably of no help but may make you think of something you had not considered.

Anthony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-23-04, 05:40 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
The upload script is for a family website I put together. It lets other family members add photos, and I can't really control the original width and height of the photos they submit, only the type and overall file size. I basically need the script to resize the pictures below a certain height and width when they are uploaded, or displayed. Using size attributes within the img tag doesnt always keep the size ratio of the picture, therefore the resize is a necessity.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-25-04, 02:53 AM
homm915 homm915 is offline
New Member
 
Join Date: Feb 2004
Location: Romania
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Easy

You have atached agraphic.txt (rename-it .php). Use the code and will work:

require("graphic.php");

$folder = "img/";
$original_image = $folder."picture.jpg";

$destination_width = 160;
$destination_height = 100;
$destination_width_mare = 250;
$destination_height_mare = 200;


$image = new hft_image($original_image);

$image->resize($destination_width, $destination_height, '-');
$new_file = $folder."new_image.jpg";
$image->output_resized($new_file, "JPEG");
echo("<hr>Dimension set: $destination_width, $destination_height <br>");
echo("<img src='$new_file' ><br>");
echo("Actual width=$image->image_resized_width Actual height=$image->image_resized_height<br>");
Attached Files
File Type: txt graphic.txt (13.3 KB, 235 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 09:30 PM
how to change text dynamically with image? rabbit51 JavaScript 1 02-23-04 09:35 AM
image load glitch bentley JavaScript 1 02-16-04 10:44 AM
How to change text dynamically with image? rabbit51 Script Requests 0 02-07-04 01:14 PM
Need help on a image slide show using php! xelanoimis PHP 2 10-16-03 07:51 PM


All times are GMT -5. The time now is 08:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.