|
|
Joined: Mar 2004
Posts: 118
Journeyman
|
Journeyman
Joined: Mar 2004
Posts: 118 |
Hello  I would like to make restrictions to images in posts who are using "image" and html "img" tags. How to make preg_replace in markup so that if the image size iz larger than size[x] (width ONLY) , img tag gets width and height tags also (from config I guess). And maybe put the image in "a href" tag so that user can still click it to get the whole image on screen. Reason for this is that if picture is wider than your screen you have to scroll right to read posts. This is very annoying. Here is Astarans Restrict signatures to help.
Kind regards, PaNTerSan
|
|
|
|
Joined: Mar 2004
Posts: 118
Journeyman
|
Journeyman
Joined: Mar 2004
Posts: 118 |
Also, Inline images might help - but this only works if image is attached.
Kind regards, PaNTerSan
|
|
|
|
Joined: Sep 2003
Posts: 488
Code Monkey
|
Code Monkey
Joined: Sep 2003
Posts: 488 |
Hmm, I don't think it's even possible to do this because there's no way to obtain the width/height values if the image is being loaded via http. It's easy to do with attachment images (and avatars) because those are loaded from the messageboard ftp using a defined path.
|
|
|
|
Joined: Mar 2004
Posts: 118
Journeyman
|
Journeyman
Joined: Mar 2004
Posts: 118 |
[]Twisty said: Hmm, I don't think it's even possible to do this because there's no way to obtain the width/height values if the image is being loaded via http. [/] Hm - doesn't the client create a request for EVERY img tag?
Kind regards, PaNTerSan
|
|
|
|
Joined: Sep 2003
Posts: 488
Code Monkey
|
Code Monkey
Joined: Sep 2003
Posts: 488 |
Ok I researched the getimagesize() function, and it will work with URL's if using PHP 4.0.5 or higher http://ca3.php.net/getimagesize
|
|
|
|
Joined: Sep 2003
Posts: 488
Code Monkey
|
Code Monkey
Joined: Sep 2003
Posts: 488 |
I put together this code to be added in showflat & showthreaded, but strangely, it replaces the image(s) with nothing. Not sure what's wrong but here it is anyway in case someone else can figure it out... if ($config['allowimages']) {<br /> if (preg_match("/<img src=\"([^\>]*)\">/i",$Body,$matches)) {<br /> $image_new = $matches[1];<br /> $image_new = str_replace(' ','%20',$image_new);<br /> $max_width = $config['max_image_width'];<br /> $resize_width = $config['max_image_width'];<br /> $size = getimagesize("$image_new");<br /> $width= $size[0];<br /> $height= $size[1];<br /> if ($width>$max_width){ <br /> $new_width=$resize_width;<br /> $Body = preg_replace("/<img src=\"$image_new\">/i","<a href=\"$image_new\"><img src=\"$image_new\" border=\"1\" width=\"$new_width\"></a>",$Body); <br /> }else { <br /> $new_width=$width;<br /> $Body = preg_replace("/<img src=\"$image_new\">/i","<img src=\"$image_new\" border=\"0\" width=\"$new_width\">",$Body);<br /> }<br /> }<br /> } ...where $config['max_image_width'] is defined in config.inc.php
|
|
|
|
Joined: May 2001
Posts: 550
Code Monkey
|
Code Monkey
Joined: May 2001
Posts: 550 |
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 87
Joined: December 2001
|
|
Forums63
Topics37,575
Posts293,931
Members13,824
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|
|