Jump to content

[resolved] GD image library - one single odd image


BarneyJoe

Recommended Posts

Have been using GD library, and have noticed one particular image that for some unfathomable reason doesn't want to stick to the max and min dimensions in the script I'm using.

If you look here, the image on the right is too big still :

[url=http://www.oriental-chamber.co.uk/round.php]link[/url]

The surrounding boxes are defined by the CSS :

.hloop {border:1px solid #3B1312; padding:1px;vertical-align:top; width:170px; height:210px;}
.hloop img {margin-bottom:7px;}

The code generating the thumbnail images is :

[code]
<a href="details.php?CarpetID=<?php echo $row_chineseDesigns['CarpetID']; ?>"><img src="thumb.php?file=Photos/<?php echo $row_chineseDesigns['Image'];?>" border="0"></a>[/code]

Where thumb.php sets the max and min dimensions of the image :

[code=php:0]<?php
// Max Sizes
$th_max_width = 140;  // Maximum width of the thumbnail
$th_max_height = 180; // Maximum height of the thumbnail

//-------------------

// File
$filename = $_GET['file'];

// Get image sizes, type & mime
$img_data = getimagesize($filename);
$width = $img_data[0];
$height = $img_data[1];
$img_type = $img_data[2]; // Numeric value (check in manual)
$mime = $img_data['mime'];

// Content type
header('Content-type: ' . $mime);


// Resize
$ratio = ($width > $height) ? $th_max_width/$width : $th_max_height/
$height;
$newwidth = round($width * $ratio);
$newheight = round($height * $ratio);

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);

switch ($img_type){
case 1:
  $source = imagecreatefromgif($filename);
  break;

case 2:
  $source = imagecreatefromjpeg($filename);
  break;
//  Other file types...
}

//Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight,   
$width, $height);

// Output
imagejpeg($thumb);
?>

<?php
exit;
?> [/code]

So the box is set to 170x210 in the CSS, and the max dimensions set in the thumb.php is 140x180.

If you look at the links on the left for the other styles, everything else is just as it should be, but on this page that one image on the right insists on breaking that max height and width.

As is so often the way there always has to be something to drive me nuts - any ideas what's causing this?

Cheers,
Iain
Link to comment
Share on other sites

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.