Jump to content


This topic is now archived and is closed to further replies.


Image size checking script

Recommended Posts

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:

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/>";
echo "<br/>";
$finalInfo = array();
//end of main foreach loop


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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)

Share this post

Link to post
Share on other sites


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.