This is a very simple one. This will allow you to search images by size.
First, use phpmyadmin or similar to run this SQL. Be sure to change 4images_ to your prefix if you used something else.
ALTER TABLE `4images_images` ADD `image_width` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `image_height` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'
Then in /admin/plugins create an empty file called set_sizes.php and paste inside:
<?php
/* Created By Zhono */
$root_path = (false === stristr($_SERVER['PHP_SELF'], "/plugins/")) ? "./../" : "./../../";
define('ROOT_PATH', $root_path);
include(ROOT_PATH.'config.php');
include(ROOT_PATH.'includes/db_mysql.php');
include(ROOT_PATH.'includes/constants.php');
$site_db = new Db($db_host, $db_user, $db_password, $db_name) OR die("HAHAHAHAHA! You Fail At Life!");
$sql = "SELECT image_id, cat_id, image_name, image_media_file, image_keywords, image_width, image_height
FROM ".IMAGES_TABLE."
WHERE image_width = '0'
OR image_height = '0'";
$result = $site_db->query($sql);
if(mysql_num_rows($result)!=0){
$worknum = 0;
while ($row = $site_db->fetch_array($result)){
$image_id = $row['image_id'];
$image_name = $row['image_name'];
$cat_id = $row['cat_id'];
$image_file = $row['image_media_file'];
$image_keywords = $row['image_keywords'];
$worknum = $worknum + 1;
$imgsize = @GetImageSize($root_path."/data/media/".$cat_id."/".$image_file);
$imgwidth = $imgsize[0];
$imgheight = $imgsize[1];
$image_width = $imgwidth;
$image_height = $imgheight;
if ($image_width == '' || $image_height == '') {
echo "There was a problem checking the image file dimension.";
exit;
}
if ($image_keywords == '') {
$image_keywords = $image_width."x".$image_height; //You can edit these to include
} else {
$image_keywords = $image_keywords.",".$image_width."x".$image_height; //other keywords if you want
}
echo $worknum.".<br>\n";
echo "<a href=\"/details.php?image_id=".$image_id."\" target=\"_blank\">Image ID: ".$image_id."</a><br>\n";
echo "Image Name: ".$image_name."<br>\n";
echo "Filename: ".$image_file."<br>\n";
echo "Real Size: ".$imgwidth."x".$imgheight."<br>\n";
echo "Set Size: ".$image_width."x".$image_height."<br>\n";
echo "Keywords Set To: ".$image_keywords."<br><hr>\n";
$sql = "UPDATE ".IMAGES_TABLE." SET image_width = '$image_width', image_height='$image_height', image_keywords='$image_keywords' WHERE image_id = '$image_id'";
$result = mysql_query($sql) OR die("HAHAHAHAHA! You Fail At Life!");
}
@mysql_close($site_db);
} else {
echo "All images sizes are currently set.";
@mysql_close($site_db);
}
?>
Also you might want to open db_field_definitions.php and add:
$additional_image_fields['image_width'] = array('Width');
$additional_image_fields['image_height'] = array('Height');
Now you can edit width and height in the admin panel.
Now just go to your AdminCP and click set_sizes.php in the plugin section. It will get the width and height of the image file and set each one in the database.
It will also add WIDTHxHEIGHT(such as 1024x768) as a keyword. It checks to make sure it doesn't delete the keywords you already have, too. You will want to run this plugin whenever there are new images added to the gallery.
After that, just run the "Rebuild Search Index" plugin that comes with 4images. Now try it! Go to your gallery search page and type in a size as a keyword. You can type just one like "768" or the whole thing "1024x768". The new width and height values are also very useful in other mods and for building various templates.
That's it for this one, enjoy. Also, watch for a few other simple admin tools that I'll be posting. Maybe I'll just add them to this thread, instead of making a thread for each one.