<?php

	require_once(dirname(__FILE__).'/_plugin.php');

	class Image_Plugin extends Plugin
	{
		function Parse($image, $url)
		{
			// exif_read_data only reads from a file so we need to save the file to disk first
			$tmpfname = tempnam(TEMP_DIRECTORY, "FOO");
			if ($tmpfname === false) {
				return '';
			}
			$save_ok = file_put_contents($tmpfname, $image);

			// Read the actual EXIF information from the image
			$exif_data = exif_read_data($tmpfname);

			// Remove our temporary file after we are done with it
			unlink($tmpfname);

			// Grab any information you are interested in and keep it to return
			$output = '';
			foreach ($exif_data as $key => $section) {
				foreach ($section as $name => $val) {
					$output .= "$key.$name: $val\n";
				}
			}
			return $output;
		}
		function Check()
		{
			if (!function_exists('exif_read_data')) {
				return false;
			}

			return true;
		}
	}

	if (!function_exists('file_put_contents')) {
		function file_put_contents($filename, $data)
		{
			$fp = fopen($filename, "w+b");
			if (!$fp) {
				return false;
			}
			$bytes_written = fwrite($fp, $data, strlen($data));
			fclose($fp);
			if ($bytes_written === false) {
				return false;
			} else {
				return $bytes_written;
			}
		}
	}


?>
