![]() |
![]() |
![]() |
|
|||||||
| New! Use your Facebook, Google, AIM & Yahoo accounts to securely log into this site, click logo to login |
|
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |
|
Learning Life's Lessons
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:
__________________
A lost temper indicates only an untrained mind. |
|
|
|
|
|
|
#3 (permalink) |
|
Lover - Protector - Teacher
|
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:
__________________
If you struggle with something your entire life, try harder. Awareness without action is worthless, and failure is not an accident. Last edited by Jinn; 05-24-2007 at 10:22 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 10:31 AM.. |
|
|
|
![]() |
| Bookmarks |
| Tags |
| function, image, php, resize |
| Thread Tools | |
|
|