Previous Thread
Next Thread
Print Thread
Rate Thread
#279523 09/12/2004 6:52 AM
Joined: Mar 2004
Posts: 118
Journeyman
Journeyman
Offline
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
Sponsored Links
Joined: Mar 2004
Posts: 118
Journeyman
Journeyman
Offline
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
Offline
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

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


Code
       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
Offline
Joined: May 2001
Posts: 550


Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Bill B
Bill B
Issaquah, WA
Posts: 87
Joined: December 2001
Forum Statistics
Forums63
Topics37,575
Posts293,931
Members13,824
Most Online6,139
Sep 21st, 2024
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Gizmo 1
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2025 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.1
(Snapshot build 20240918)