Jump to content

Recommended Posts

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';
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/109633-solved-setting-a-max-height/
Share on other sites

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);
?>

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);
  }
}

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

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);
   }
}

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.

?><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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.