Forum Moderators: coopster
my code:
<?php
header('Content-type: image/jpeg');
$myimage = resizeImage('images/Bikini006.jpg', '120', '80');
function resizeImage($filename, $newwidth, $newheight){
list($width, $height) = getimagesize($filename);
if($width > $height && $newheight < $height){
$newheight = $height / ($width / $newwidth);
} else if ($width < $height && $newwidth < $width) {
$newwidth = $width / ($height / $newheight);
} else {
$newwidth = $width;
$newheight = $height;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagejpeg($thumb);
}
print resizeImage('images/Bikini006.jpg', '120', '80');
?>
so how can i save the modified version to a directory on the server from this script?
thanks in advance for your time!
-Ken
so in your case,
imagejpeg($thumb, '/somedir/newpicture.jpg',100); would write that new image to a new file, at 100% quality
-sned
// make directory for thumbnails
mkdir($site . '/' . $gallery . '/thumbnails', 0707);
// save the image
imagejpeg($img, $site . '/' . $gallery . '/thumbnails/' . $image_file, '95');
}
You should be able to customise them to do what you want.
my code so far:
<?php
header('Content-type: image/jpeg');
$myimage = resizeImage('images/Bikini006.jpg', '120', '80');
function resizeImage($filename, $newwidth, $newheight){
list($width, $height) = getimagesize($filename);
if($width > $height && $newheight < $height){
$newheight = $height / ($width / $newwidth);
} else if ($width < $height && $newwidth < $width) {
$newwidth = $width / ($height / $newheight);
} else {
$newwidth = $width;
$newheight = $height;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagejpeg($thumb);
imagejpeg($thumb, '/u/a/atticnet/www.domain.com/gallery/images/thumbs/Bikini006.jpg',100);
}
print resizeImage('images/Bikini006.jpg', '120', '80');
?>
any ideas what i'm doing wrong here?
thanks again for your time!
-Ken
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, '/u/a/atticnet/www.domain.com/gallery/images/thumbs/Bikini006.jpg',100);
return imagejpeg($thumb);
I can't remember for sure, but I think code placed after a return may not get executed.
-sned