~adamzammit/quexf/swinburnequexf

291 by Adam Zammit
Replace short tags with full php tags
1
<?php
1 by azammitdcarf
Initial import
2
3
/*	Copyright Deakin University 2007,2008
4
 *	Written by Adam Zammit - adam.zammit@deakin.edu.au
5
 *	For the Deakin Computer Assisted Research Facility: http://www.deakin.edu.au/dcarf/
6
 *	
7
 *	This file is part of queXF
8
 *	
9
 *	queXF is free software; you can redistribute it and/or modify
10
 *	it under the terms of the GNU General Public License as published by
11
 *	the Free Software Foundation; either version 2 of the License, or
12
 *	(at your option) any later version.
13
 *	
14
 *	queXF is distributed in the hope that it will be useful,
15
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *	GNU General Public License for more details.
18
 *	
19
 *	You should have received a copy of the GNU General Public License
20
 *	along with queXF; if not, write to the Free Software
21
 *	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 *
23
 */
24
186 by azammitdcarf
Added ICR functionality
25
1 by azammitdcarf
Initial import
26
if (isset($_GET['bgid'])){
27
47 by azammitdcarf
separated config from db file
28
	include_once("config.inc.php");
29
	include_once("db.inc.php");
1 by azammitdcarf
Initial import
30
	include("functions/functions.image.php");
31
	
32
	global $db;
33
34
	$bgid = intval($_GET['bgid']);
35
36
	$sql=  "SELECT *
128 by azammitdcarf
Removed dependency on MySQL views
37
		FROM boxes
1 by azammitdcarf
Initial import
38
		WHERE bgid = '$bgid'";
39
40
	$rows = $db->GetAll($sql);
41
42
	if (empty($rows)) exit;
43
44
	$pid = $rows[0]['pid'];
45
46
	$sql = "SELECT image 
47
		FROM pages
48
		WHERE pid = $pid";
49
50
	$row = $db->GetRow($sql);
51
52
	if (empty($row)) exit;
53
54
	$sql = "SELECT MIN(`tlx`) as tlx,MIN(`tly`) as tly,MAX(`brx`) as brx,MAX(`bry`) as bry
128 by azammitdcarf
Removed dependency on MySQL views
55
		FROM boxes
1 by azammitdcarf
Initial import
56
		WHERE bgid = '$bgid'";
57
58
	$crop = $db->GetRow($sql);
59
60
	$image = imagecreatefromstring($row['image']);
61
62
	header("Content-type: image/png");
63
64
	if (!empty($rows))
65
		imagepng(crop(overlay($image,$rows),$crop));
66
	else
67
		imagepng($image);
68
69
70
}
71 by azammitdcarf
admin/index.php: Added system setup item
71
else if (isset($_GET['filename']))
72
{
73
	$im = imagecreatefrompng($_GET['filename']);
74
	header('Content-type: image/png');
75
	imagepng($im);
76
	imagedestroy($im);
77
}
1 by azammitdcarf
Initial import
78
else if (isset($_GET['pid']))
79
{
47 by azammitdcarf
separated config from db file
80
	include("config.inc.php");
81
	include("db.inc.php");
1 by azammitdcarf
Initial import
82
	include("functions/functions.image.php");
83
	
84
	global $db;
85
	
86
	$pid = intval($_GET['pid']);
87
88
89
	if (isset($_GET['fid']))
90
	{
91
		$fid = intval($_GET['fid']);
92
186 by azammitdcarf
Added ICR functionality
93
		$sql = "SELECT * 
1 by azammitdcarf
Initial import
94
			FROM formpages
95
			WHERE pid = $pid and fid = $fid";
96
	
97
		$row = $db->GetRow($sql);
98
99
		if (empty($row)) exit;
100
265 by Adam Zammit
New Feature: Allow for images from scanned forms to be stored as files instead of in the database
101
    if ($row['filename'] == '')
102
    {
103
      $im = imagecreatefromstring($row['image']);
104
    }
105
    else
106
    {
107
      $im = imagecreatefrompng(IMAGES_DIRECTORY . $row['filename']);
108
    }
1 by azammitdcarf
Initial import
109
21 by azammitdcarf
OCR functionality
110
		if (isset($_GET['bid']))
111
		{
112
			$bid = intval($_GET['bid']);
113
			$sql = "SELECT tlx,tly,brx,bry
114
				FROM boxes
115
				WHERE bid = '$bid'";
116
			$box = $db->GetRow($sql);
117
186 by azammitdcarf
Added ICR functionality
118
			$row['width'] = imagesx($im);
119
			$row['height'] = imagesy($im);
120
			
121
			//$im = st_ocr($im,calcoffset($box,$row['offx'],$row['offy']));
122
			//header("Content-type: image/png");
123
			//imagepng($im);
124
			//exit;
125
			$box['tlx']+= BOX_EDGE;
126
			$box['tly']+= BOX_EDGE;
127
			$box['brx']-= BOX_EDGE;
128
			$box['bry']-= BOX_EDGE;
129
130
			header("Content-type: image/png");
131
132
			$timage = crop($im,applytransforms($box,$row));
133
134
			if(!isset($_GET['a'])){ imagepng($timage); die();}
135
//			image_to_text($timage);
136
		
22 by azammitdcarf
showpage.php displays without box edge
137
			include("functions/functions.ocr.php");
186 by azammitdcarf
Added ICR functionality
138
139
			$ktimage = kfill_modified($timage,5);
140
			//invert_image($timage);
141
142
//			if(isset($_GET['b'])){ imagepng($ktimage); die();}
143
//			 imagepng($ktimage); die();
144
//			image_to_text($ktimage);
145
146
			$ttimage = remove_boundary_noise($ktimage,2);
147
148
//			if(isset($_GET['c'])){ imagepng($ttimage); die();}
149
//			 imagepng($ttimage); die();
150
//			image_to_text($ttimage);
151
152
			$kttimage = resize_bounding($ttimage);	
153
154
//			if(isset($_GET['d'])){ imagepng($kttimage); die();}
155
//			 imagepng($kttimage); die();
156
157
158
			$i = thinzs_np($kttimage);
159
160
161
			imagepng($i);
162
			//imagepng(thin_b($timage));
163
			die();
164
		
22 by azammitdcarf
showpage.php displays without box edge
165
			$box['tlx']+= BOX_EDGE;
166
			$box['tly']+= BOX_EDGE;
167
			$box['brx']-= BOX_EDGE;
168
			$box['bry']-= BOX_EDGE;
169
21 by azammitdcarf
OCR functionality
170
			header("Content-type: image/png");
186 by azammitdcarf
Added ICR functionality
171
			imagepng(crop($im,applytransforms($box,$row)));
21 by azammitdcarf
OCR functionality
172
		}
173
		else
174
		{
38 by azammitdcarf
updated to allow for zooming
175
			if (isset($_GET['zoom']))
176
			{
177
				header("Content-type: image/png");
281 by Adam Zammit
Fixed Bug: Image not displaying when zoomed and not in database
178
				imagepng($im);
38 by azammitdcarf
updated to allow for zooming
179
			}
180
			else
181
			{
182
				$width = imagesx($im);
183
				$height = imagesy($im);
184
		
47 by azammitdcarf
separated config from db file
185
				$newwidth = DISPLAY_PAGE_WIDTH;
186
				$newheight = round($height * (DISPLAY_PAGE_WIDTH/$width));
38 by azammitdcarf
updated to allow for zooming
187
		
188
				$thumb = imagecreatetruecolor($newwidth, $newheight);
189
				imagepalettecopy($thumb,$im);
190
		
191
				imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
192
		
193
				header("Content-type: image/png");
194
				imagepng($thumb);
195
			}
21 by azammitdcarf
OCR functionality
196
		}
1 by azammitdcarf
Initial import
197
	}
198
	else
199
	{
200
		$sql = "SELECT image 
201
			FROM pages
202
			WHERE pid = $pid";
203
	
204
		$row = $db->GetRow($sql);
205
206
		if (empty($row)) exit;
207
47 by azammitdcarf
separated config from db file
208
		header("Content-Type: image/png");
1 by azammitdcarf
Initial import
209
		echo ($row['image']);
210
211
	}
212
213
}
214
215
216
?>