0

is there a way to resize an image after you have uploaded it using php? suppose i want to restrict the width and height of my images to 1000 and 800 respectively what code to i add to the following code snippet?

$tmp_file = $_FILES['file_upload']['tmp_name'];
        $target_file = basename( $_FILES['file_upload']['name'] );
        $upload_dir = IMAGE_DIR;
        
        if ( move_uploaded_file( $tmp_file, IMAGE_DIR . "/" . $target_file ) ) {
            $message = "File has been successfully uploaded.";
        } else {
            $error = $_FILES['file_upload']['error'];
            $message = $upload_errors[$error];       
        }
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by kamili
1

Depending on what you have installed, you can use the GD library or ImageMagick. You can search this forum for examples.

Edited by pritaeas: n/a

0

As pritaeas suggested, you can make sure you have the GD library and PHP5, then use the either the Simple Image class by Simon Jarvis and/or the Resize Class by Jarrod Oberto with the following kind of call:

$image->load($uploadedfile);
$image->resize(width,height);
$image->save($pathtoresizedimagefilename);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.