TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-02-2008, 12:29 PM   #1 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default Changing imagesize while uploading.

Hi Guys!

I have done a uploading script, but I want to do, so when I upload an image the image should be stored in 3 different sizes. That means 3 different pictures. What is the easiest way to do that? Here is my upload-script:

PHP Code:
$filename 'billeder/' basename($_FILES['file']['name']);


        if (
move_uploaded_file($_FILES['file']['tmp_name'], $filename)) {
            echo 
"File is valid, and was successfully uploaded.";
        } else {
            echo 
'DEBUG: Fra: ' $_FILES['file']['tmp_name'] . ' til ' $filename '<br>';
            echo 
"Possible file upload attack!";
        }    

        
$sql "INSERT INTO smykker (smykkenavn, beskrivelse, pris, varenr, billede, kategori, underkategori, leveringstid)
            VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
;
        
$sql sprintf($sql,
            
mysql_real_escape_string($_POST['smykkenavn']),
            
mysql_real_escape_string($_POST['beskrivelse']),
            
mysql_real_escape_string($_POST['pris']),
            
mysql_real_escape_string($_POST['varenr']),
            
mysql_real_escape_string($filename),
            
mysql_real_escape_string($_POST['kategori']),
            
mysql_real_escape_string($_POST['underkategori']),
            
mysql_real_escape_string($_POST['leveringstid'])
            );

        
$res mysql_query($sql) or die(mysql_error());
        echo 
"Done<br>Klik <a href='upload.php'>her</a> for at gå tilbage."
lesP is offline  
Reply With Quote
Old 04-09-2008, 06:57 AM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

with imagecopyresampled() you can do that quite easily. And in your code, please check the file for mimetype and extention! :)
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 04-10-2008, 01:50 PM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Jim View Post
with imagecopyresampled() you can do that quite easily. And in your code, please check the file for mimetype and extention! :)
...or imagecopyresized incase he doesn't want it to change the pixels.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 04-10-2008, 07:00 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

easy really, here the script i use:
PHP Code:
function resizeImage($originalImage,$toWidth,$toHeight,$dest_img)
{
    list(
$width$height) = getimagesize($originalImage);
    
$xscale=$width/$toWidth;
    
$yscale=$height/$toHeight;

    if (
$yscale>$xscale)
   {
        
$new_width round($width * (1/$yscale));
        
$new_height round($height * (1/$yscale));
    }
    else 
    {
        
$new_width round($width * (1/$xscale));
        
$new_height round($height * (1/$xscale));
    }
    
$imageResized imagecreatetruecolor($new_width$new_height);
    
$imageTmp imagecreatefromjpeg ($originalImage);
    
imagecopyresampled($imageResized$imageTmp0000$new_width$new_height$width$height);

    
imagejpeg($imageResized$dest_img);
}

resizeImage('test1.jpg'400400'test_res2222222.jpg'); 
I have used this in the past, should be easy for you to modify, it takes into account image orientation (i.e. landscape/portrait) and scales accoringly. It olny accepts jpegs atm but like i say you its easy to customize it with the correct image format function. the php manual is useful here:

PHP: Image - Manual
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 04:50 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design