An PHP based Image Database
Go to file
2013-06-08 14:01:29 -05:00
code Removed unnecessary unlink from uploader and changed date for the uploads to be based on file time. This allows you to copy files to the server preserving the time it was made and go to /upload/complete to have them processed. Fixed me being lazy so that users can enter a quotation mark without having issues of the HTML code being outputted wrong. Fixed the search field so that it also corrects the HTML output rather than outputting raw data. Added the ability to search by date. Enter a date or a "to: from:" query and it will search the database by that date range. 2013-06-08 14:01:29 -05:00
css Image Database Start 2013-06-02 19:19:30 -05:00
data Image Database Start 2013-06-02 19:19:30 -05:00
databases Image Database Start 2013-06-02 19:19:30 -05:00
external_data_plugins Image Database Start 2013-06-02 19:19:30 -05:00
img Image Database Start 2013-06-02 19:19:30 -05:00
js Image Database Start 2013-06-02 19:19:30 -05:00
load Image Database Start 2013-06-02 19:19:30 -05:00
thumbs Image Database Start 2013-06-02 19:19:30 -05:00
.htaccess Image Database Start 2013-06-02 19:19:30 -05:00
dbSQLITE.php Image Database Start 2013-06-02 19:19:30 -05:00
footer.php Image Database Start 2013-06-02 19:19:30 -05:00
header.php Removed unnecessary unlink from uploader and changed date for the uploads to be based on file time. This allows you to copy files to the server preserving the time it was made and go to /upload/complete to have them processed. Fixed me being lazy so that users can enter a quotation mark without having issues of the HTML code being outputted wrong. Fixed the search field so that it also corrects the HTML output rather than outputting raw data. Added the ability to search by date. Enter a date or a "to: from:" query and it will search the database by that date range. 2013-06-08 14:01:29 -05:00
index.php Image Database Start 2013-06-02 19:19:30 -05:00
License.txt Image Database Start 2013-06-02 19:19:30 -05:00
ocr.cpp Image Database Start 2013-06-02 19:19:30 -05:00
ocr.sh Image Database Start 2013-06-02 19:19:30 -05:00
readme.md Removed unnecessary unlink from uploader and changed date for the uploads to be based on file time. This allows you to copy files to the server preserving the time it was made and go to /upload/complete to have them processed. Fixed me being lazy so that users can enter a quotation mark without having issues of the HTML code being outputted wrong. Fixed the search field so that it also corrects the HTML output rather than outputting raw data. Added the ability to search by date. Enter a date or a "to: from:" query and it will search the database by that date range. 2013-06-08 14:01:29 -05:00

#Requirements 1: pdo sqlite

2: gd

3: Due to my coding style, you must allow short tags "<?" in php.

4: Installation of ImageMagick. You can test this by typing "convert" in terminal. If needed, you can change configuration in index.php for the bin path.

#Installation 1: Copy all files to your server.

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.

3: Visit the database on your server and the setup process will commence.

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.

#Setting up your server ##Nginx Here is the configuration you need to add to your nginx server.

location ~* /(databases|load|code|external_data_plugins) {
	rewrite ^ /index.php?$args;
}
location ~* /(data|thumbs)/.*(?<\!\.gif|\.png|\.jpg|\.jpeg|\.tif|\.tiff)$ {
	rewrite ^ /index.php?$args;
}
location / {
	try_files $uri $uri/ /index.php?$args;
}

It is best to placet the ones with "rewrite" above your php include.

You can test by visiting /code/index.php to see if it loads the index file or if it shows a 404 error.

##Apache 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.

#Getting OCR to work. I've included code to OCR images for text. It's not perfect, but it provides great power.

In-order to use it, you must first install OpenCV and 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.

#Writing an External Data Plugin 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.

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.

<?
$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_URL => "http://mrgeckosmedia.com/some-api",
	CURLOPT_POSTFIELDS => array(
		"md5" => $hash
	),
	CURLOPT_RETURNTRANSFER => true
));
$received = json_decode(curl_exec($ch), true);
curl_close($ch);
if (isset($received['result']['tags'])) {
	if (!empty($external_data))
		$external_data .= " ";
	//Append to the "$external_data" variable with the description to provide rich content.
	$external_data .= $received['result']['description'];
	
	//Prefill Tags in database.
	$dtags = explode(" ", $received['result']['tags']);
	for ($i=0; $i<count($dtags); $i++) {
		if (!in_array($dtags[$i], $tags))
			array_push($tags, $dtags[$i]);
	}
}
?>

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.

#Known Problems 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.

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.