Jump to content

shrinking a blog including images down to 200px width


dachshund

Recommended Posts

hi,

 

i have a blog on my website, which i would like to include on the main page in a condensed down format as well as on its separate blog page.

 

in the 'content' part there is both text and images, all the images are uploaded to my hosting at 500px wide.

 

on the main page i would like the blog to be condensed down to 200px wide, the only problem is these images are 500px and i don't know how to resize them because there's text in there as well.

 

is there anyway to find out if there are images in the post, and if there are, resize them proportionally to 200px wide.

 

my code at the moment looks something like this

 

<?php

$sql="SELECT * FROM entries ORDER BY id DESC LIMIT 5";
$result=mysql_query($sql);
?>

<table width="100%" border="0" align="center" cellpadding="5">

<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
	<td align="left" bgcolor="#FFFFFF" class="blogtitle" valign="top" colspan="2">
	<? echo $rows['title']; ?>
	</td>
</tr>
<tr>
	<td align="left" bgcolor="#FFFFFF" valign="top" colspan="2">
	<? echo $rows['content']; ?>
	</td>
</tr>
<tr>
	<td align="left" bgcolor="#FFFFFF" class="bottomborder" valign="bottom"><? echo $rows['date']; ?></td>
	<td align="right" class="bottomborder" valign="bottom"><? echo $rows['postedby']; ?></td>
</tr>

<?php
}
mysql_close();
?>

</table>

 

any help would be much appreciated.

 

thanks

 

 

 

The exact code would depend on the format of the image tags in your blog content, but couldn't you just load the blog post into a php variable, and use something like str_replace("<img width = 500", "<img width = 200", $blog_content_var) ?

 

If the imgage tags are not consistant, you could use a regex to find and replace them.

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.