05-24-2007, 07:34 AM | #1 (permalink) | |
Registered User
Location: Right Here
|
PHP Image resize function
I have the GD library installed and running. I can't get this script to work, any suggestions? The picture displays, but not at the size I want.
Quote:
|
|
05-24-2007, 09:18 AM | #3 (permalink) |
Lover - Protector - Teacher
Location: Seattle, WA
|
Two things:
1) I see the function declaration, but where is the actual call? Do you have a separate block of code which calls it? I don't see you passing a height, width, target to imageResize. You get it with getimagesize, but never pass that value to the function? Also, without a function call, where is that return value going? It's going nowhere at the moment. It looks like you're trying to accomplish something like: PHP Code:
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel Last edited by Jinn; 05-24-2007 at 09:22 AM.. |
05-24-2007, 09:25 AM | #4 (permalink) |
Huggles, sir?
Location: Seattle
|
This is some old code I used to generate a thumbnail from an uploaded image, which may help.
For reference, check out the PHP image function documentation. Code:
$fullsize = $user_id . "_" . time() . "_" . $_FILES['shot']['name']; $thumb = "thumb_" . $user_id . "_" . time() . "_" . $_FILES['shot']['name']; move_uploaded_file( $_FILES['shot']['tmp_name'], $shot_directory . "/" . $fullsize ); list( $width, $height, $type, $attr ) = getimagesize( $shot_directory . "/" . $fullsize ); if ( $type == 1 ) $src = imagecreatefromgif( $shot_directory . "/" . $fullsize ); else if ( $type == 2 ) $src = imagecreatefromjpeg( $shot_directory . "/" . $fullsize ); else return "ERROR: This gallery only supports JPG and GIF file formats"; // creating a thumbnail ---------------------------------------------------------- $multiplier = 160 / $width; $new_width = 160; $new_height = round( $height * $multiplier ); if ( $new_height > 160 ) { $multiplier = 0; $new_height = 0; $new_width = 0; $multiplier = 160 / $height; $new_height = 160; $new_width = round( $width * $multiplier ); } $dest = imagecreatetruecolor( $new_width, $new_height ); imageCopyResampled( $dest, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); imagejpeg( $dest, $shot_directory . "/" . $thumb );
__________________
seretogis - sieg heil perfect little dream the kind that hurts the most, forgot how it feels well almost no one to blame always the same, open my eyes wake up in flames Last edited by seretogis; 05-24-2007 at 09:31 AM.. |
Tags |
function, image, php, resize |
|
|