Reply
image resizing script on upload
Old 04-08-2008, 01:56 PM image resizing script on upload
Super Talker

Posts: 122
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
 
When You Register, These Ads Go Away!
Old 04-08-2008, 03:29 PM Re: image resizing script on upload
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
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.
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 

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
Super Talker

Posts: 122
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,062
Name: Mike
Location: Mataro, Spain
Do not use imagecopyresmapled() to resize images, use ImageMagick's "convert" utility instead.

http://www.webmaster-talk.com/php-fo...e-resizer.html
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is online now
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
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
Lol... why use a page of code when one line will do?
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
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,062
Name: Mike
Location: Mataro, Spain
They like using pure php solutions
__________________
Free Mobile Phone Themes

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

Thread Tools

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

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