Jump to content


Photo

Image size checking script


  • Please log in to reply
3 replies to this topic

#1 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 23 July 2006 - 05:07 PM

Hi i wrote a script that would go through all of the members on my forums and check there signature image sizes:
now it works great for one person but it is taking an extremely long time to go through the entire thing, and i was wondering if i had coded something wrong or someone knows a way to optomise the script:

here is an example signature from the db:
[IMG]http://www.sighost.us/members/lalias/tyler1z.jpg[/IMG]
[IMG]http://www.ufdf.com/sigs/officially-gay.png[/IMG][img]http://img97.imageshack.us/img97/7767/clanbitch9ns.png[/img][img]http://www.ufdf.com/sigs/ufdf-member.png[/img][img]http://img74.imageshack.us/img74/5104/clanslut8fk.png[/img][img]http://www.ufdf.com/sigs/moocat-lover.png[/img]
[img]http://www.ufdf.com/sigs/sci-fi-freak.png[/img][img]http://www.ufdf.com/sigs/luke's-bitch.png[/img][img]http://www.ufdf.com/sigs/-canada.png[/img][img]http://www.ufdf.com/sigs/-gaypride.png[/img]

<?PHP
set_time_limit(0);
require_once('Connections/connPASSWORD.php');
mysql_select_db($database_connPASSWORD, $connPASSWORD);
$query_RsSig = "SELECT u.username, t.signature FROM vb3_usertextfield t, vb3_user u WHERE (t.userid = u.userid) AND (t.signature <> '') AND (u.usergroupid = 26)";
$RsSig = mysql_query($query_RsSig, $connPASSWORD) or die(mysql_error());
$row_RsSig = mysql_fetch_assoc($RsSig);
$totalRows_RsSig = mysql_num_rows($RsSig);
//set variables
$imageLine = 1;
$height = 0;
$width = 0;
$maxheight = 500;
$maxwidth = 600;
//create an array called data where the assosiative name is the persons username, and set the value to the signature value
do {
$data[$row_RsSig['username']] = $row_RsSig['signature'];
} while ($row_RsSig = mysql_fetch_assoc($RsSig));
	//valuedata is username cheesedata is the signature
	foreach ($data as $valuedata => $cheesedata){
	//create an array called sigdata and and split it line by line.
	$sigdata = explode("\r\n",$cheesedata);
	//create a loop for every single line of the array
		foreach ($sigdata as $value => $cheese){
		//check if the data matches the regex and if it does put the link to the image in the matches array.
		preg_match_all('/\\[IMG\\](.+?)\\[\/IMG]/i', $cheese, $match);
		
		//get the number of images in the current matches array
		$numImages = count($match[1]);
		if($numImages != 0){
			foreach ($match[1] as $value1 => $cheese1){
			$imagedata = getimagesize($cheese1);
			
			$height1 = $imagedata[1];
			
				if($height1 > $height){
				$height = $height1;
				}
			
			$width = $width + $imagedata[0];
			
			$siginfo["Line$imageLine"]['width'] = $width;
			$siginfo["Line$imageLine"]['height'] = $height;
		$width = 0;
		$height1 = 0;
		$height = 0;			
			}
			$finalInfo['height'] = $finalInfo['height'] + $siginfo["Line$imageLine"]['height'];
				if($siginfo["Line$imageLine"]['width'] > $finalInfo['width']){
				$finalInfo['width'] = $siginfo["Line$imageLine"]['width'];
				}
			}
		//reset variables

		$imageLine ++;
		$sigdata = array();
		$siginfo = array();
		}
	if($finalInfo['height'] > $maxheight or $finalInfo['width'] > $maxwidth){
	echo $valuedata ;
	echo "<br/>";
	var_dump($finalInfo);
	echo "<br/>";
	}
	$finalInfo = array();
	//end of main foreach loop
	}
mysql_free_result($RsSig);
?>



#2 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 23 July 2006 - 05:35 PM

There is probobly a way to optamise it, but, heck, going throgh EVERY user in a databse (even a few hundred) is an intesive task. You could always ignore user abort and not worry how long it takes, if you only intend to run it every once in a while.
http://php.net/manua...-user-abort.php
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#3 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 23 July 2006 - 05:37 PM

yeah i know, i mean considering that some users have like 20 images in their sig it is a nightmare for me.
so i am thinking i was going to run it as a cron job and make it generate a text file with the names of people who are over limit or something?

But do you know any other way to optomise it?

#4 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 23 July 2006 - 05:39 PM

Personally, i would run it once, and modify the code that allows them to edit their signatures to check for image size (thus eliminating the need for an intensive cron)
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users