2 replies [Last post]
jwrbloom
jwrbloom's picture
Offline
newbie
Last seen: 3 years 20 weeks ago
Timezone: GMT-5
Joined: 2010-03-06
Posts: 6
Points: 9

This may not be a CSS question, but I'm using variables to determine height and width of an image with in a PHP file.

$height = 330;
$width = 270;

I'd like to set those as max-height and max-width so smaller images aren't stretched.

jwrbloom
jwrbloom's picture
Offline
newbie
Last seen: 3 years 20 weeks ago
Timezone: GMT-5
Joined: 2010-03-06
Posts: 6
Points: 9

Don't exactly know why

Don't exactly know why max-height and max-width don't work just within the code itself, but here is the code I'm referring to. It's a WordPress theme:

<a href="<?php echo($arr[$i]["permalink"]); ?>" title="<?php printf(__('Permanent Link to %s', 'TheCorporation'), $arr[$i]["fulltitle"]) ?>">
 
<?php print_thumbnail($arr[$i]["Feature"], $arr[$i]["use_timthumb"], $arr[$i]["fulltitle"] , $width, $height, 'thumb'); ?>
					</a>

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 1 year 30 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

query the image to get its

query the image to get its dimensions then determine exact height and width values.

$img = getimagesize('path/to/image');
list($w,$h) = $img;
 
// compare $w & $h to max width and max height and determine what actual width and height to use ...
 
echo '<img src="url/of/image" alt="" width="'.$width.'" height="'.$height.'" />';