Forum Moderators: coopster
im making a website for photographers, some images uploaded are vertical, some are horizontal, when we look at the gallery of the pics i dont want the pics to appear too big on the screen and pull the table all over, or, be too small in their box and get stretched.
what i wanna do is put images on display in a box about 100px in width x height, but let them look natural in shape exactly like my favorite free image site - can anyone tell me how to get the file size and resize the images in proportion irregardless of if they are a vertical or horizontal picture.
im stuck,
if you feel like a proper challenge i also want to create a pop up div function that displays the database entry big version of the image that floats.
or am i pushing my luck ;)
thanx in advance
diegomh7
[edited by: jatar_k at 8:30 pm (utc) on Sep. 4, 2006]
[edit reason] no urls thanks [/edit]
// Filename to store image as (no extention)
$FILENAME = 'some_name'// Maxmium width and height to reszie image to (in pixels)
$RESIZEWIDTH = 180;
$RESIZEHEIGHT = 180;
// Temporary directory to upload image to (CHMOD 775 or 777)
$uploaddir = "/path/to/image/directory/";
function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) ¦¦ ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name . ".jpg","90");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$name . ".jpg","90");
}
}
if($_FILES['image']['size']){
move_uploaded_file($image, "$uploaddir"."$image_name");
if($_FILES['image']['type'] == "image/pjpeg" ¦¦ $_FILES['image']['type'] == "image/jpeg"){
$im = imagecreatefromjpeg("$uploaddir"."$image_name");
}elseif($_FILES['image']['type'] == "image/x-png" ¦¦ $_FILES['image']['type'] == "image/png"){
$im = imagecreatefrompng("$uploaddir"."$image_name");
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$uploaddir.$FILENAME);
ImageDestroy ($im);
unlink("$uploaddir"."$image_name");