2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Wrapper script for rendering transformations
12 define('IS_TRANSFORMATION_WRAPPER', true);
15 * Gets a core script and starts output buffering work
17 require_once './libraries/common.inc.php';
18 require_once './libraries/transformations.lib.php'; // Transformations
19 $cfgRelation = PMA_getRelationsParam();
22 * Ensures db and table are valid, else moves to the "parent" script
24 require_once './libraries/db_table_exists.lib.php';
28 * Sets globals from $_REQUEST
30 $request_params = array(
40 foreach ($request_params as $one_request_param) {
41 if (isset($_REQUEST[$one_request_param])) {
42 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
48 * Get the list of the fields of the current table
50 $GLOBALS['dbi']->selectDb($db);
51 if (isset($where_clause)) {
52 $result = $GLOBALS['dbi']->query(
53 'SELECT * FROM ' . PMA_Util
::backquote($table)
54 . ' WHERE ' . $where_clause . ';',
56 PMA_DatabaseInterface
::QUERY_STORE
58 $row = $GLOBALS['dbi']->fetchAssoc($result);
60 $result = $GLOBALS['dbi']->query(
61 'SELECT * FROM ' . PMA_Util
::backquote($table) . ' LIMIT 1;',
63 PMA_DatabaseInterface
::QUERY_STORE
65 $row = $GLOBALS['dbi']->fetchAssoc($result);
71 } // end if (no record returned)
73 $default_ct = 'application/octet-stream';
75 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
76 $mime_map = PMA_getMime($db, $table);
77 $mime_options = PMA_Transformation_getOptions(
78 isset($mime_map[$transform_key]['transformation_options'])
79 ?
$mime_map[$transform_key]['transformation_options'] : ''
82 foreach ($mime_options as $key => $option) {
83 if (substr($option, 0, 10) == '; charset=') {
84 $mime_options['charset'] = $option;
89 // Only output the http headers
90 $response = PMA_Response
::getInstance();
91 $response->getHeader()->sendHttpHeaders();
94 if (isset($ct) && ! empty($ct)) {
97 $mime_type = (isset($mime_map[$transform_key]['mimetype'])
98 ?
str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
100 . (isset($mime_options['charset']) ?
$mime_options['charset'] : '');
103 PMA_downloadHeader($cn, $mime_type);
105 if (! isset($resize)) {
106 echo $row[$transform_key];
108 // if image_*__inline.inc.php finds that we can resize,
109 // it sets $resize to jpeg or png
111 $srcImage = imagecreatefromstring($row[$transform_key]);
112 $srcWidth = ImageSX($srcImage);
113 $srcHeight = ImageSY($srcImage);
115 // Check to see if the width > height or if width < height
116 // if so adjust accordingly to make sure the image
117 // stays smaller then the $newWidth and $newHeight
119 $ratioWidth = $srcWidth/$newWidth;
120 $ratioHeight = $srcHeight/$newHeight;
122 if ($ratioWidth < $ratioHeight) {
123 $destWidth = $srcWidth/$ratioHeight;
124 $destHeight = $newHeight;
126 $destWidth = $newWidth;
127 $destHeight = $srcHeight/$ratioWidth;
131 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
134 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
135 // $destWidth, $destHeight, $srcWidth, $srcHeight);
136 // better quality but slower:
138 $destImage, $srcImage, 0, 0, 0, 0, $destWidth,
139 $destHeight, $srcWidth, $srcHeight
142 if ($resize == 'jpeg') {
143 ImageJPEG($destImage, null, 75);
145 if ($resize == 'png') {
146 ImagePNG($destImage);
148 ImageDestroy($srcImage);
149 ImageDestroy($destImage);