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
image resizing script on upload
Old 04-08-2008, 01:56 PM image resizing script on upload
Extreme Talker

Posts: 177
Trades: 0
The user can upload a jpeg for their avatar, but I want to keep it to a certain size, and I'm running into an error...

PHP Code:
$regexp ereg_replace(" """$_FILES['newPic']['name']);
$max_width=200;
            
$max_height=200;
            
            
$src $_FILES["newPic"]["tmp_name"];
            list(
$width,$height) = getimagesize($_FILES["newPic"]["tmp_name"]);
            
            
$x_ratio $max_width $width;
            
$y_ratio $max_height $height
            
            if( (
$width <= $max_width) && ($height <= $max_height) )
            {
                
$tn_width $width;
                
$tn_height $height;
            }
            elseif ((
$x_ratio $height) < $max_height)
            {
                
$tn_height ceil($x_ratio $height);
                
$tn_width $max_width;
            }
            else
            {
                
$tn_width ceil($y_ratio $width);
                
$tn_height $max_height;
            }

            
$tmp=imagecreatetruecolor($tn_width,$tn_height);
            
$src3 imagecreatefromjpeg($src);
            
imagecopyresampled($tmp,$src3,0,0,0,0,$tn_width$tn_height,$width,$height);
            
            
//puts the file in the pictures directory
            
move_uploaded_file($tmp,
            
"files/Pictures/" $regexp); 
But when everything gets executed, it doesn't save the file to the destination address. Any ideas? Thanks.

edit: sometimes this error pops up
Code:
 Warning:  imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/k/b/f/kbfirebreather/html/checkSettingsChanged.php on line 93 


Last edited by kbfirebreather; 04-08-2008 at 01:59 PM.. Reason: got an error
kbfirebreather is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-08-2008, 03:29 PM Re: image resizing script on upload
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I'm guessing (and I really mean guessing here) $src3 is not correct in,
PHP Code:
imagecopyresampled($tmp,$src3,0,0,0,0,$tn_width$tn_height,$width,$height); 
Take a look at http://uk2.php.net/manual/en/functio...yresampled.php it might have something.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 04-08-2008 at 03:31 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-08-2008, 03:39 PM Re: image resizing script on upload
Extreme Talker

Posts: 177
Trades: 0
me too, but I'm not to sure what's wrong
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-09-2008, 01:32 AM Re: image resizing script on upload
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Do not use imagecopyresmapled() to resize images, use ImageMagick's "convert" utility instead.

http://www.webmaster-talk.com/php-fo...e-resizer.html
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-09-2008, 05:19 AM Re: image resizing script on upload
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Lol... why use a page of code when one line will do?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 02:25 AM Re: image resizing script on upload
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
They like using pure php solutions
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to image resizing script on upload
 

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.47231 seconds with 12 queries