Jump to content

[SOLVED] Dynamic image resize, width & height


Alexhoward

Recommended Posts

Hello guys,

 

I've got this script from the PHP manual:

 

<?php

while($row = mysql_fetch_array($sub_results)) { 
    $title = $row['title']; 
    $image1 = $row['image1'];
    $fdesc = SUBSTR($row['fdesc'],0,400);
    $user = $row['username'];
    $ref = $row['ref'];


     $image =  "$image1";                
     $size = getimagesize("$image");
       $height = $size[1];
       $width = $size[0];
     if ($height > 100)
          {
               $height = 100;
               $percent = ($size[1] / $height);
               $width = ($size[0] / $percent);
          }
     else if ($width > 100)
          {
               $width = 100;
               $percent = ($size[0] / $width);
               $height = ($size[1] / $percent);
          }
     //echo "<img src\"image/path/image.jpg\" height=\"$height\" width=\"$width\" />";

?>

 

The top part is the end of my select query...

 

Problem is it's not working as i hoped.

 

What i'd like to do is fit whatever sized image into a 100 X 100 cell,

 

so i just assumed take whatever length is bigger and make it 100, then the other dimension would just scale proportionally.

 

However this is not what it's doing.

 

Could any of you suggest how i change this...?

 

Thanks in advance!

Sussed!

 

This'll do the job...

 

<?php

while($row = mysql_fetch_array($sub_results)) { 
    $title = $row['title']; 
    $image1 = $row['image1'];
    $fdesc = SUBSTR($row['fdesc'],0,400);
    $user = $row['username'];
    $ref = $row['ref'];


     $image =  "$image1";                
     $size = getimagesize("$image");
       $height = $size[1];
       $width = $size[0];
     if ($height > $width)
          {
               $height = 100;
               $percent = ($size[1] / $height);
               $width = ($size[0] / $percent);
          }
     else if ($width > $height)
          {
               $width = 100;
               $percent = ($size[0] / $width);
               $height = ($size[1] / $percent);
          }
     //echo "<img src\"image/path/image.jpg\" height=\"$height\" width=\"$width\" />";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.