eevan79 Posted July 17, 2010 Share Posted July 17, 2010 How to check size of image in post (text) and replace it with url? Example: "click on this image: [img ]http://link_to_image.jpg[/img ] I need to check if img tags exists in post and check size in kb of that image. If size >=200kb (example) than replace tags with: [url ]http://link_to_image.jpg[/url ]. This is code that I use to replace all [ img] tags with [ url] $text = str_replace ("[img ]","[url ]",$text ); $text = str_replace ("[/img ]","[/url ]",$text ); This code doesnt check image size, but replace all images with urls. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted July 17, 2010 Author Share Posted July 17, 2010 I found function that check file size (remote) function remote_filesize($url, $user = "", $pw = "") { ob_start(); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); if(!empty($user) && !empty($pw)) { $headers = array('Authorization: Basic ' . base64_encode("$user:$pw")); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $ok = curl_exec($ch); curl_close($ch); $head = ob_get_contents(); ob_end_clean(); $regex = '/Content-Length:\s([0-9].+?)\s/'; $count = preg_match($regex, $head, $matches); return isset($matches[1]) ? $matches[1] : "unknown"; } echo remote_filesize($text,'',''); How to use this function to check images in posts? First I need to find url between [ img] [/ img] tags and than use this function to check. If file size is >= 200 replace this [ img] tags with Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 17, 2010 Share Posted July 17, 2010 Why not just thumbnail images, and link from the thumbnail? Then the user doesn't have to open the full resolution image to decide if he wants to open the full resolution image. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted July 17, 2010 Author Share Posted July 17, 2010 Not bad idea, but it also need to check if there is image in post and then thumbnail that image. Anyway, I think Its better to replace image with link. I dont want to create thumbs if there is small images. Also, I have tested getimagesize and its very slow if there is more than one image. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.