[HELP?][CSS] Possible to do a "If image is wider then xxx pxls, width=100%, else, nothing"

Zakk-

Junior Member
Joined
Sep 16, 2009
Messages
141
Reaction score
15
Okay, I pretty much explained it in the title, but here we go.

I have been messing around with a wordpress theme to get it to fit my needs, however, I ran into a problem. The images in the posts cover up my sidebar as they are too large.

What I would like to do, is to resize all images that are too wide, but leave the others as they are.

So in pseudo code...
Code:
If
   image is over xxx pixels, 
       set the width to 100%
else
   nothing



Can anyone help me out?
 
Not sure about css but...

Code:
<?php
list($width, $height, $type, $attr) = getimagesize("your_image.jpg");

if($width > $max_width){
echo "<img src='your_image.jpg' style='INLINE CSS STYLING'>";
} else {
echo "<img src='your_image.jpg'>";
}
?>

Basically you want to let php check the images dimensions then if it's larger than your max width you echo an altered image html where you specify the CSS code inline and if it isn't then you echo the regular image code.
 
Back
Top