An PHP based Image Database
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.8 KiB

  1. #Requirements
  2. 1: [pdo sqlite](http://php.net/manual/en/ref.pdo-sqlite.php)
  3. 2: [gd](http://php.net/manual/en/book.image.php)
  4. 3: Due to my coding style, you must allow [short tags](http://php.net/manual/en/ini.core.php) \("<?"\) in php.
  5. 4: Installation of [ImageMagick](http://www.imagemagick.org/script/index.php). You can test this by typing "convert" in terminal. If needed, you can change configuration in index.php for the bin path.
  6. #Installation
  7. 1: Copy all files to your server.
  8. 2: Change permissions to folders databases, load, data, and thumbs so that php can write to them. If you do not know the correct permissions, 777 will work but is inscure on shared servers.
  9. 3: Visit the database on your server and the setup process will commence.
  10. 4: Once you have finished the setup process. You may delete the setup file in the code folder if you do not want to allow anyone to setup a new database if for some reason the file gets currupted.
  11. #Setting up your server
  12. ##Nginx
  13. Here is the configuration you need to add to your nginx server.
  14. ```text
  15. location ~* /(databases|load|code|external_data_plugins) {
  16. rewrite ^ /index.php?$args;
  17. }
  18. location ~* /(data|thumbs)/.*(?<\!\.gif|\.png|\.jpg|\.jpeg|\.tif|\.tiff)$ {
  19. rewrite ^ /index.php?$args;
  20. }
  21. location / {
  22. try_files $uri $uri/ /index.php?$args;
  23. }
  24. ```
  25. It is best to placet the ones with "rewrite" above your php include.
  26. You can test by visiting /code/index.php to see if it loads the index file or if it shows a 404 error.
  27. ##Apache
  28. For Apache, i've already included the .htaccess files needed. Just make sure your server is configured to allow htaccess and mod_rewrite. Best test by visiting /code/index.php.
  29. #Getting OCR to work.
  30. I've included code to OCR images for text. It's not perfect, but it provides great power.
  31. In-order to use it, you must first install [OpenCV](http://opencv.org/) and [Tesseract-OCR]([https://code.google.com/p/tesseract-ocr/). Then you should just be able to run ```./ocr.sh``` in terminal with the image database directory as your current working directory. Only tested on OS X.
  32. #Writing an External Data Plugin
  33. External Data plugins allows you to write plugins which grabs data from another site about an image and put it into the metadata to make search better. For an example, if there is an image tag site which contains your image and good tags, you could write your plugin to grab the tags and store them so when you search for say green, your image will popup as the tag green was on that image via the site.
  34. Writing a plugin is simple. Make a new file in the folder external_data_plugins and then put your code inside of it to grab the data and fill the database.
  35. ```php
  36. <?
  37. $ch = curl_init();
  38. curl_setopt_array($ch, array(
  39. CURLOPT_URL => "http://mrgeckosmedia.com/some-api",
  40. CURLOPT_POSTFIELDS => array(
  41. "md5" => $hash
  42. ),
  43. CURLOPT_RETURNTRANSFER => true
  44. ));
  45. $received = json_decode(curl_exec($ch), true);
  46. curl_close($ch);
  47. if (isset($received['result']['tags'])) {
  48. if (!empty($external_data))
  49. $external_data .= " ";
  50. //Append to the "$external_data" variable with the description to provide rich content.
  51. $external_data .= $received['result']['description'];
  52. //Prefill Tags in database.
  53. $dtags = explode(" ", $received['result']['tags']);
  54. for ($i=0; $i<count($dtags); $i++) {
  55. if (!in_array($dtags[$i], $tags))
  56. array_push($tags, $dtags[$i]);
  57. }
  58. }
  59. ?>
  60. ```
  61. You have access to many variables about the file being processed including it's name and extension. Just look at code/upload.php to see what is available.
  62. #Known Problems
  63. There isn't any error reporting in the API and there isn't anyway for the user to know that such an error such as network issues or database issues occured.
  64. There isn't a way for users to to sign up. If I were to implement one... The admin would be able to choose rather to allow signups or not.