Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: transformation_wrapper.php,v 2.13.2.1 2006/03/10 13:41:01 lem9 Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4  
5 define('IS_TRANSFORMATION_WRAPPER', true);
6  
7 /**
8 * Gets a core script and starts output buffering work
9 */
10 require_once('./libraries/common.lib.php');
11 require_once('./libraries/relation.lib.php'); // foreign keys
12 require_once('./libraries/transformations.lib.php'); // Transformations
13 $cfgRelation = PMA_getRelationsParam();
14  
15 /**
16 * Ensures db and table are valid, else moves to the "parent" script
17 */
18 require_once('./libraries/db_table_exists.lib.php');
19  
20  
21 /**
22 * Get the list of the fields of the current table
23 */
24 PMA_DBI_select_db($db);
25 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
26 if (isset($primary_key)) {
27 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', null, PMA_DBI_QUERY_STORE);
28 $row = PMA_DBI_fetch_assoc($result);
29 } else {
30 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
31 $row = PMA_DBI_fetch_assoc($result);
32 }
33  
34 // No row returned
35 if (!$row) {
36 exit;
37 } // end if (no record returned)
38  
39 $default_ct = 'application/octet-stream';
40  
41 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
42 $mime_map = PMA_getMime($db, $table);
43 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
44  
45 foreach ($mime_options AS $key => $option) {
46 if (substr($option, 0, 10) == '; charset=') {
47 $mime_options['charset'] = $option;
48 }
49 }
50 }
51  
52 // garvin: For re-usability, moved http-headers and stylesheets
53 // to a seperate file. It can now be included by libraries/header.inc.php,
54 // querywindow.php.
55  
56 require_once('./libraries/header_http.inc.php');
57 // [MIME]
58 if (isset($ct) && !empty($ct)) {
59 $content_type = 'Content-Type: ' . urldecode($ct);
60 } else {
61 $content_type = 'Content-Type: ' . (isset($mime_map[urldecode($transform_key)]['mimetype']) ? str_replace('_', '/', $mime_map[urldecode($transform_key)]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
62 }
63 header($content_type);
64  
65 if (isset($cn) && !empty($cn)) {
66 header('Content-Disposition: attachment; filename=' . urldecode($cn));
67 }
68  
69 if (!isset($resize)) {
70 echo $row[urldecode($transform_key)];
71 } else {
72 // if image_*__inline.inc.php finds that we can resize,
73 // it sets $resize to jpeg or png
74  
75 $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
76 $srcWidth = ImageSX( $srcImage );
77 $srcHeight = ImageSY( $srcImage );
78  
79 // Check to see if the width > height or if width < height
80 // if so adjust accordingly to make sure the image
81 // stays smaller then the $newWidth and $newHeight
82  
83 $ratioWidth = $srcWidth/$newWidth;
84 $ratioHeight = $srcHeight/$newHeight;
85  
86 if ($ratioWidth < $ratioHeight){
87 $destWidth = $srcWidth/$ratioHeight;
88 $destHeight = $newHeight;
89 } else {
90 $destWidth = $newWidth;
91 $destHeight = $srcHeight/$ratioWidth;
92 }
93  
94 if ($resize) {
95 $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
96 }
97  
98 // ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
99 // better quality but slower:
100 ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
101  
102 if ($resize == 'jpeg') {
103 ImageJPEG( $destImage, '', 75 );
104 }
105 if ($resize == 'png') {
106 ImagePNG( $destImage);
107 }
108 ImageDestroy( $srcImage );
109 ImageDestroy( $destImage );
110 }
111  
112 /**
113 * Close MySql non-persistent connections
114 */
115 if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) {
116 @PMA_DBI_close($GLOBALS['controllink']);
117 }
118 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
119 @PMA_DBI_close($GLOBALS['userlink']);
120 }
121 ?>