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

 

 

 

Link to comment
Share on other sites

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.

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.