Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Resample & copy image
Old 05-10-2005, 06:09 PM Resample & copy image
Skilled Talker

Posts: 61
Trades: 0
I'm having a ridiculous amount of trouble making this script work. Primarily I think because I don't really understand the php image functions, and am fairly inexperienced in PHP in general.

Basically, I want to take a user-uploaded image and resize it proportionally, then copy it to the server. I can upload no problem, but when I try to do all the createtruecolor copyresampled functions, I'm way over my head.

(there are some references in there to thumbnail images that don't yet do anything)

Here's the code so far:

PHP Code:
// UPLOAD IMAGE TO SERVER
            
            
$gallery $_POST['gallery'];
            
$name $_POST['name'];
            
$caption $_POST['caption'];
            
            
$directory_full '../../gallery/images/';
            
$directory_thumb '../../gallery/images/';
            
            
$postfixFull '_full';
            
$postfixThumb '_thumb';
            
$ext '.jpg';
            
            
$srcImage $_FILES['image'];
        
            
$maxWidthFull 500;
            
$maxWidthThumb 100;
        

            if(!empty(
$_FILES['image'])){
            
                if(
$_FILES['image']['type']!="image/jpeg"){
                    die(
'Image must be a JPEG');
                    }
                
                
// rename image, create sub names
                
$imageName str_replace($ext,"",str_replace(" ","",$_FILES['image']['name']));
                
$imageNameFull $imageName $postfixFull $ext;
                
$imageNameThumb $imageName $postfixThumb $ext;
                
                
                
// RESIZE IMAGE BY MAX WIDTH
                
$sizes getimagesize($_FILES['image']['tmp_name']);
                
$aspect_ratio $sizes[0] / $sizes[1]; // width / height
                
                
if($sizes[0] <= $maxWidthFull){
                    
$newWidthFull $sizes[0];
                    
$newHeightFull $sizes[1];
                    }
                else{
                    
$newWidthFull $maxWidthFull;
                    
$newHeightFull abs($newWidthFull/$aspect_ratio);
                    }
                     
                
// create full size image dimension block
                
$destImageFull imagecreatetruecolor($newWidthFull$newHeightFull);
                
// 
                
$imageFinalFull imagecopyresampled($destImageFull$srcImage0000$newWidthFull$newHeightFull$sizes[0], $sizes[1]);
                
                
                
                
// COPY AND RESIZE THUMBNAIL TO MAX WIDTH
                
                
                
                // copy resized image to server
                
move_uploaded_file($_FILES['image']['tmp_name'], $directory_full $imageFinalFull
                    or 
                    die (
'Could not upload');
                
                
// copy thumbnail to server
                
                
                // NOW ADD INFO TO DATABASE
                 
mysql_query("INSERT INTO gallery VALUES (
                    '',
                    '
$name',
                    '
$gallery',
                    '
$caption',
                    '
$imageNameThumb',
                    '
$imageNameFull'
                    )"
);
                 
                 
                 print(
'<br>Image uploaded');
                
                }
            else{
                print 
'file empty';
                } 
I've been reading the PHP manual on this stuff and I really just don't understand it. Hoping someone can explain what's going on here. Really appreciate it.
gregory is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Resample & copy image
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28357 seconds with 12 queries