Jump to content

'Advanced' BBCode


Perad

Recommended Posts

What I want to do is allow users on my website to upload images. The problem is that large images will break my website and look terrible.

 

As a result I want to limit the the size of the images. I already know how to do this. The problem I am having is working out how I can actually insert this code.

 

Currently I am using an array which is then shipped off into a preg_match statement as follows.

 

$this->MatchReplace = array (
'/\[img\](.*?)\[\/img\]/is' => '<img src="$1" />', // Image
);

foreach($this->MatchReplace as $key => $val) {
$this->str = preg_replace ($key, $val, $this->str);
}

 

I need to change this to allow me to run the following fuction.

 

public function imageResize($url, $maxwidth, $maxheight) {
	$fetch = getimagesize($url);
	$width = $fetch[0];
	$height = $fetch[1];

	if ($width > $maxwidth || $height > $maxheight) {
		if ($width > $height) {
			$percentage = ($maxwidth / $width);
		} else {
			$percentage = ($maxheight / $height);
		}

		//gets the new value and applies the percentage, then rounds the value
		$width = round($width * $percentage);
		$height = round($height * $percentage);

		//returns the new sizes in html image tag format...this is so you

		$this->imageDimensions = "width=\"$width\" height=\"$height\"";
	}
}

 

Would I need to use preg_match to do this? If so could someone demonstrate how this would be done?

Link to comment
https://forums.phpfreaks.com/topic/88713-advanced-bbcode/
Share on other sites

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.