Author Topic: [MOD]+[ADMIN PLUGIN] Search by image size  (Read 13074 times)

0 Members and 1 Guest are viewing this topic.

Offline zhono

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[MOD]+[ADMIN PLUGIN] Search by image size
« on: January 25, 2013, 07:14:35 PM »
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.
Code: [Select]
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:
Code: [Select]
<?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:
Code: [Select]
$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.

Offline Szooguun

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #1 on: April 09, 2013, 04:15:39 PM »
Welcome. Sorry for my english. I am using the module "Show original image in new window by clicking on image" - As in this case modify this mod "Search by image size" to fetch image sizes of the folders "big"?

Offline zhono

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #2 on: April 09, 2013, 06:39:41 PM »
Hello Szooguun,

I think all you would need to do is find:

Code: [Select]
$imgsize = @GetImageSize($root_path."/data/media/".$cat_id."/".$image_file);
And replace with:

Code: [Select]
$imgsize = @GetImageSize($root_path."/data/media/".$cat_id."/big/".$image_file);
If you have any trouble, let me know.

Offline Szooguun

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #3 on: April 09, 2013, 08:18:07 PM »
Works. Thank you very much.

PS. For several thousand images I added the image size as a tag. Is it possible to modify the script so that the second time is not added, the size of a photo tag?
« Last Edit: April 09, 2013, 09:49:49 PM by Szooguun »

Offline Szooguun

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #4 on: May 09, 2013, 03:06:01 PM »
It gave me the size to about 2 000 pictures and got the message: HAHAHAHAHA! You Fail At Life! I want to add size to more than 30 000 pictures - what to do? Help, please.

Offline zhono

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #5 on: May 10, 2013, 09:35:27 PM »
I'm not sure why that would happen. If you don't already have keywords, or don't mind them being removed, I can give you an altered version of the script that will overwrite the keywords with just the image width-height. It'll also skip the ones it already did each time, so you can get through them all.

I'll try to build a better solution soon.

Offline Szooguun

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #6 on: May 13, 2013, 12:37:09 PM »
If you don't already have keywords, or don't mind them being removed, I can give you an altered version of the script that will overwrite the keywords with just the image width-height. It'll also skip the ones it already did each time, so you can get through them all.

I have keywords assigned to all the images and do not want to lose them. I would like now to all wallpapers add the keyword: picture size, without losing any previously added keywords describing the photo.

I'll try to build a better solution soon.

I look forward to a solution that will add the image size to a few tens of thousands of photos. Yours.

Offline Szooguun

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: [MOD]+[ADMIN PLUGIN] Search by image size
« Reply #7 on: May 13, 2015, 04:02:30 PM »
Refresh