Forum Moderators: coopster

Message Too Old, No Replies

ph gd image resizing

ph gd image resizing

         

adrianbromfield

2:39 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



Hi guys, im trying to use some gd functions to resize my images on upload. ive read tutorials and stuff on this and everything seems good, no errors. however my images stay the same. i want the file itself to be resized not just to display resized if that makes sense.

here is what i have..

function imgresize($img){
// Load image

$image = @imagecreatefromjpeg($img);
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$pos = strpos($img,"BIG.jpg");
if($pos === false){
$new_width = 201;
$new_height = 158;
}
else{
$new_width = 531;
$new_height = 480;
}

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

}

can anyone explain what im doing rong.. as i feel i may not be understanding the functions properly.

thanks,

adrian

whoisgregg

3:12 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The thing that jumps out at me is that you aren't outputting back out the resized image.

Sends direct to browser:

header('Content-type: image/jpeg');
[url=http://php.net/imagejpeg]imagejpeg[/url]($image_resized, null, 90);

Saves to disk:

$filepath = $_SERVER['DOCUMENT_ROOT'].'/imgs/resized/'.$img;
[url=http://php.net/imagejpeg]imagejpeg[/url]($image_resized, $filepath, 90);

adrianbromfield

8:46 am on Aug 20, 2007 (gmt 0)

10+ Year Member



hi, thanks for your response,

i had already tried what you have written.. though seeing you say this and probably having the weekend to take my mind off it for abit has made me look into what else i could be doing wrong, but clearer as i never spotted it before.

I was using the wrong variable for the filepath! Foolish lol!..

thanks alot, works all fine and dandy now! :D