Jump to content

editing html image code


volatileboy

Recommended Posts

Hey just a quick question, I have made a forum and I am using a standard bbcode method which include url, I am stumped in finding a way to resize the dimensions of the image when the code is loaded onto the page.

 

My problem isn't with the actual image resize, it's searching through the post text for the string match, getting out the parts I need and changing it with the new width and height.

 

Does anyone have any help on this cos it's kicking my ass?

 

Thanks for reading!

Link to comment
https://forums.phpfreaks.com/topic/112565-editing-html-image-code/
Share on other sites

Sorry, my post was a little confusing, not to mention I didnt use code tags lol.

 

Basically in user posts they can insert image urls like this forum with [ img] [ /img] tags, this is then converted with preg_replace, a shortened version of which is shown below:

 

$patterns = array("/\[url\](.*?)\[\/url\]/","/\[img\](.*?)\[\/img\]/");
$replacements = array("<a href=\"\\1\">\\1</a>","<img border=0 src='\\1'>");
$str = preg_replace($patterns,$replacements, $str);

 

This conversion from bbcode to html is done on page load and the images come out like this:

 

<img border="0" src="http://www.url.com/picture.jpg">

 

I want to scan through the post and check for legit image tags or [img ] tags, use getimagesize() to find out it's dimensions and calculate it's new width and height and then replace the initial image string with a new one that won't destroy my page.

 

If this can be done easier with CSS that would be great, I can't say im a pro with CSS but it would be a much easier option.

 

Thanks!

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.