4images Forum & Community
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2014, 03:04:40 PM

Login with username, password and session length
Search:     Advanced search
Togle to toolbar
Translate this page with =>
Translate this page >
* Home Help Search Login Register
 
+  4images Forum & Community
|-+  4images Modifications / Modifikationen
| |-+  Mods & Plugins (Requests & Discussions) (Moderators: mawenzi, Rembrandt)
| | |-+  [MOD]+[ADMIN PLUGIN] Search by image size
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: [MOD]+[ADMIN PLUGIN] Search by image size  (Read 4220 times)
zhono
Jr. Member
**
Offline Offline

Posts: 52

Thank You
-Given: 3
-Receive: 9


View Profile
« 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.
1
2
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?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:
1
2
$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.
Logged
Szooguun
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 4
-Receive: 0


View Profile
« 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"?
Logged
zhono
Jr. Member
**
Offline Offline

Posts: 52

Thank You
-Given: 3
-Receive: 9


View Profile
« Reply #2 on: April 09, 2013, 06:39:41 PM »

Hello Szooguun,

I think all you would need to do is find:

1
$imgsize = @GetImageSize($root_path."/data/media/".$cat_id."/".$image_file);

And replace with:

1
$imgsize = @GetImageSize($root_path."/data/media/".$cat_id."/big/".$image_file);

If you have any trouble, let me know.
Logged
Szooguun
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 4
-Receive: 0


View Profile
« 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 » Logged
Szooguun
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 4
-Receive: 0


View Profile
« 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.
Logged
zhono
Jr. Member
**
Offline Offline

Posts: 52

Thank You
-Given: 3
-Receive: 9


View Profile
« 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.
Logged
Szooguun
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 4
-Receive: 0


View Profile
« 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.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.146 seconds with 19 queries.
Post your comments here