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
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.