think-digitally Posted June 10, 2008 Share Posted June 10, 2008 Hi. I need to set a max height in a photo gallery of mine, there is already a width of 165px, but when you put a portrait style photograph in its maaaahooosive. So I wanted to limit it to 165 height, keeping the image ratio. Does anyone know how to do this? Here is the gallery code: <?php require_once 'header2.php'; $time_stamp = date("d.m.Y"); $date = $time_stamp; ?> <tr><td><table align="center"> <?php ///////////////////////////////////////////////////////////// if(isset($_GET['image_cat'])) { $cater = $_GET['image_cat']; $_SESSION['image_cat'] = $cater; $query = "SELECT sub_cat FROM `sub_cat` WHERE `parent_cat` = '{$cater}'"; $result = mysql_query($query) or die("Error:" . mysql_error()); $i = 0; ?> <tr><td><div id="image_gal"><a href="image_gallery.php">Galleries</a> > <?php echo $cater;?></div></td></tr> <tr><td><table width="0" align="center"> <tr><td><tr> <?php while ($row = mysql_fetch_assoc($result)) { if ($i == 3) { $i = 0; // reset variable echo "<tr>"; // break the line } $car = $row['sub_cat']; $sql = "SELECT * FROM image_gallery WHERE `sub_folder`='{$car}' ORDER BY RAND() LIMIT 1"; $reslt = mysql_query($sql) or die ("Error:" . mysql_error()); $rw = mysql_fetch_assoc($reslt); ?><td class="style8"><b><?php echo $row['sub_cat']; ?></b></font><br><a href="?image_subcat=<?php echo $row['sub_cat']; ?>"><img width="165px" height="165px" src="images/thumbs/<?php echo $rw['image_link']; ?>"></a></td><td> </td> <?php $i++; // increase $i each time through the loop } ?> </td></tr><tr><td> </td></tr></table></td></tr> <?php if (mysql_num_rows($result) < 1) { echo "<tr><td>No Images Yet.</td></tr><tr><td>Keep Checking Back</td></tr>"; } require_once 'footer.php'; exit(); } ///////////////////////////////////////////////////////////// if(isset($_GET['image_subcat'])) // If the URL ends in ?image_cat do everything in the brakets { $sub_cat = $_GET['image_subcat']; $query = "SELECT folder_name,image_link,image_id,image_name,sub_folder FROM `image_gallery` WHERE `sub_folder` = '{$sub_cat}' ORDER BY image_id ASC"; $result = mysql_query($query) or die("Error:" . mysql_error()); $i = 0; ?> <tr><td><div id="image_gal"><a href="image_gallery.php">Galleries</a> > <a href="?image_cat=<?php echo $_SESSION['image_cat'];?>"><?php echo $_SESSION['image_cat'];?></a> > <?php echo $sub_cat;?></div></td></tr> <tr><td><table align="center"><tr> <?php while ($row = mysql_fetch_assoc($result)) { if ($i == 3) { $i = 0; // reset variable echo "</tr><tr><td> </td></tr><tr>"; // break the line } ?><td><a href="images/<?php echo $row['image_link']; ?>" rel="lightbox [main]" title="<?php echo $row['image_name']; ?>" ><img width="165px" src="images/thumbs/<?php echo $row['image_link']; ?>"></a><br><?php echo $row['image_name']; ?></td> <?php $i++; // increase $i each time through the loop } ?> </td></tr><tr><td> </td></tr></table></td></tr> <?php require_once 'footer.php'; exit(); } ///////////////////////////////////////////////////////////// //No ID passed to page, display user list: ?> <table width="100%" bgcolor="#e5e5e5" id="1"> <tr> <td width="2%"> </td> <td width="98%" height="30" class="style4"><div align="left">Galleries</div> </font></td> </tr> <tr> <td> </td> <td class="style6"><div align="left">Please choose a gallery below, and use the in-gallery navagation to take a look around.</div> </font></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table> <?php $query = "SELECT catergory,image_link FROM `image_catergory` ORDER BY catergory ASC"; $result = mysql_query($query) or die("Error:" . mysql_error()); $i = 0; ?> <tr><td><table align="center"> <tr> <?php while ($row = mysql_fetch_assoc($result)) { if ($i == 3) { $i = 0; // reset variable echo "</tr><tr>"; // break the line } $car = $row['catergory']; $sql = "SELECT * FROM image_gallery WHERE `folder_name`='{$car}' ORDER BY RAND() LIMIT 1"; $reslt = mysql_query($sql) or die ("Error:" . mysql_error()); $rw = mysql_fetch_assoc($reslt); ?><td><a href="?image_cat=<?php echo $row['catergory']; ?>" class="style4>"<b><?php echo $row['catergory']; ?></b></font><br><img width="165px" src="images/thumbs/<?php echo $rw['image_link']; ?>"></a></td><td> </td> <?php $i++; // increase $i each time through the loop } ?> </td></tr><tr><td> </td></tr><table> <?php if (mysql_num_rows($result) < 1) { echo "<tr><ts>No Images Yet.</td></tr><tr><td>Keep Checking Back</td></tr>"; } if($_SESSION['log_in'] == true) { ?> <?php } require_once 'footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/ Share on other sites More sharing options...
revraz Posted June 10, 2008 Share Posted June 10, 2008 That would be done with CSS or HTML. Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562375 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 By doing this surely this will resize all images to that height? Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562390 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 maybe it is this part of the code that resizes the images needs to be edited? <?php $imgpath = $image; $thumbpath = $_SERVER['DOCUMENT_ROOT'] . "/images/thumbs/" . $_FILES['uploaded']['name']; $img = imagecreatefromjpeg($imgpath); list($imgwidth,$imgheight) = getimagesize($imgpath); //edit this section to change image width,height $flagwidth = 165; $percent = round(($flagwidth/$imgwidth) * 165) * .01; $newimgwidth = $imgwidth * $percent; $newimgheight = $imgheight * $percent; //end section $newimage = imagecreatetruecolor($newimgwidth, $newimgheight); imagecopyresampled($newimage, $img,0,0,0,0,$newimgwidth, $newimgheight, $imgwidth, $imgheight); imagejpeg($newimage, $thumbpath,165); ?> Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562397 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 Simple, check to see if height is greater than width... if it is, use a ratio based on height, if not, use a ratio based on width. Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562403 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 Sorry I am on a beginner... could you give me an example? Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562407 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 The answer is in your code Please tell me you know how to use if/thens and variable definitions! If not, then you need more help than I can provide Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562414 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 Can you provide the code for me? Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562419 Share on other sites More sharing options...
lemmin Posted June 10, 2008 Share Posted June 10, 2008 If you change what is between the "edit this" comment section to the code below, it should scale all images to a max of either 165 height or 165 width. if ($imgwidth >= 165 || $imgheight >= 165) { if ($imgwidth > $imgheight) { $imgwidth = 165; $imgheight = 165*($imgheight/$imgwidth); } else { $imgheight = 165; $imgwidth = 165*($imgwidth/$imgheight); } } Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562422 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 it displays these errors Warning: imagecreatetruecolor(): Invalid image dimensions in /home/content/a/1/6/a16538296/html/upload.php on line 120 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/a/1/6/a16538296/html/upload.php on line 123 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/content/a/1/6/a16538296/html/upload.php on line 125 Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562429 Share on other sites More sharing options...
lemmin Posted June 10, 2008 Share Posted June 10, 2008 Woops, I meant to use $newimagewidth and $newimageheight. Here is the fixed code: if ($imgwidth >= 165 || $imgheight >= 165) { if ($imgwidth > $imgheight) { $newimgwidth = 165; $newimgheight = 165*($imgheight/$imgwidth); } else { $newimgheight = 165; $newimgwidth = 165*($imgwidth/$imgheight); } } Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562435 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 If you keep getting people to code for you, you'll never know how to fix things when they break. Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562438 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 Fantastic, thanks, it works, but it doesnt display correct in the gallery, would you mind looking at this, what would I need to do to change this? ?><td><a href="images/<?php echo $row['image_link']; ?>" rel="lightbox [main]" title="<?php echo $row['image_name']; ?>" ><img width="165px" src="images/thumbs/<?php echo $row['image_link']; ?>"></a><br><?php echo $row['image_name']; ?></td> <?php and discomatt, I am learning, but this needs to be done asap. I need my website back online. Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562451 Share on other sites More sharing options...
discomatt Posted June 10, 2008 Share Posted June 10, 2008 Hire a programmer. This is a PHP help board... you're not asking for help, you're asking for someone to code for you. Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562457 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 Christ! If you dont want to help, then dont, if others do, then surely it is up to them. I am grateful for the help that 'lemmin' has given me. It is possible to learn from this! Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562465 Share on other sites More sharing options...
lemmin Posted June 10, 2008 Share Posted June 10, 2008 What exactly isn't correct about the way it is being displayed? Could you post the generated html where the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562466 Share on other sites More sharing options...
DeanWhitehouse Posted June 10, 2008 Share Posted June 10, 2008 ?><td><a href="images/<?php echo $row['image_link']; ?>" rel="lightbox [main]" title="<?php echo $row['image_name']; ?>" ><img src="images/thumbs/<?php echo $row['image_link']; ?>"></a><br><?php echo $row['image_name']; ?></td> <?php remove the width Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562469 Share on other sites More sharing options...
think-digitally Posted June 10, 2008 Author Share Posted June 10, 2008 Thanks guys!! Much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/#findComment-562491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.