Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / transformation_wrapper.php
blobbd3d9f987c8c65a2e17055011573b4f4e7afc3a9
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
11 define('IS_TRANSFORMATION_WRAPPER', true);
13 /**
14 * Gets a core script and starts output buffering work
16 require_once './libraries/common.inc.php';
17 require_once './libraries/transformations.lib.php'; // Transformations
18 $cfgRelation = PMA_getRelationsParam();
20 /**
21 * Ensures db and table are valid, else moves to the "parent" script
23 require_once './libraries/db_table_exists.lib.php';
26 /**
27 * Sets globals from $_REQUEST
29 $request_params = array(
30 'cn',
31 'ct',
32 'newHeight',
33 'newWidth',
34 'resize',
35 'sql_query',
36 'transform_key',
37 'where_clause'
39 foreach ($request_params as $one_request_param) {
40 if (isset($_REQUEST[$one_request_param])) {
41 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
46 /**
47 * Get the list of the fields of the current table
49 PMA_DBI_select_db($db);
50 if (isset($where_clause)) {
51 $result = PMA_DBI_query(
52 'SELECT * FROM ' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';',
53 null,
54 PMA_DBI_QUERY_STORE
56 $row = PMA_DBI_fetch_assoc($result);
57 } else {
58 $result = PMA_DBI_query(
59 'SELECT * FROM ' . PMA_Util::backquote($table) . ' LIMIT 1;',
60 null,
61 PMA_DBI_QUERY_STORE
63 $row = PMA_DBI_fetch_assoc($result);
66 // No row returned
67 if (! $row) {
68 exit;
69 } // end if (no record returned)
71 $default_ct = 'application/octet-stream';
73 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
74 $mime_map = PMA_getMime($db, $table);
75 $mime_options = PMA_transformation_getOptions(
76 isset($mime_map[$transform_key]['transformation_options'])
77 ? $mime_map[$transform_key]['transformation_options'] : ''
80 foreach ($mime_options AS $key => $option) {
81 if (substr($option, 0, 10) == '; charset=') {
82 $mime_options['charset'] = $option;
87 // Only output the http headers
88 $response = PMA_Response::getInstance();
89 $response->getHeader()->sendHttpHeaders();
91 // [MIME]
92 if (isset($ct) && ! empty($ct)) {
93 $mime_type = $ct;
94 } else {
95 $mime_type = (isset($mime_map[$transform_key]['mimetype'])
96 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
97 : $default_ct)
98 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
101 PMA_downloadHeader($cn, $mime_type);
103 if (! isset($resize)) {
104 echo $row[$transform_key];
105 } else {
106 // if image_*__inline.inc.php finds that we can resize,
107 // it sets $resize to jpeg or png
109 $srcImage = imagecreatefromstring($row[$transform_key]);
110 $srcWidth = ImageSX($srcImage);
111 $srcHeight = ImageSY($srcImage);
113 // Check to see if the width > height or if width < height
114 // if so adjust accordingly to make sure the image
115 // stays smaller then the $newWidth and $newHeight
117 $ratioWidth = $srcWidth/$newWidth;
118 $ratioHeight = $srcHeight/$newHeight;
120 if ($ratioWidth < $ratioHeight) {
121 $destWidth = $srcWidth/$ratioHeight;
122 $destHeight = $newHeight;
123 } else {
124 $destWidth = $newWidth;
125 $destHeight = $srcHeight/$ratioWidth;
128 if ($resize) {
129 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
132 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
133 // $destWidth, $destHeight, $srcWidth, $srcHeight);
134 // better quality but slower:
135 ImageCopyResampled(
136 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
137 $destHeight, $srcWidth, $srcHeight
140 if ($resize == 'jpeg') {
141 ImageJPEG($destImage, null, 75);
143 if ($resize == 'png') {
144 ImagePNG($destImage);
146 ImageDestroy($srcImage);
147 ImageDestroy($destImage);