Translated using Weblate (Japanese)
[phpmyadmin.git] / transformation_wrapper.php
blob23a8107f5dba163034d6742969707e9d1d0ab4e8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Wrapper script for rendering transformations
6 * @package PhpMyAdmin
7 */
9 /**
12 define('IS_TRANSFORMATION_WRAPPER', true);
14 /**
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();
21 /**
22 * Ensures db and table are valid, else moves to the "parent" script
24 require_once './libraries/db_table_exists.lib.php';
27 /**
28 * Sets globals from $_REQUEST
30 $request_params = array(
31 'cn',
32 'ct',
33 'newHeight',
34 'newWidth',
35 'resize',
36 'sql_query',
37 'transform_key',
38 'where_clause'
40 foreach ($request_params as $one_request_param) {
41 if (isset($_REQUEST[$one_request_param])) {
42 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
47 /**
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 . ';',
55 null,
56 PMA_DatabaseInterface::QUERY_STORE
58 $row = $GLOBALS['dbi']->fetchAssoc($result);
59 } else {
60 $result = $GLOBALS['dbi']->query(
61 'SELECT * FROM ' . PMA_Util::backquote($table) . ' LIMIT 1;',
62 null,
63 PMA_DatabaseInterface::QUERY_STORE
65 $row = $GLOBALS['dbi']->fetchAssoc($result);
68 // No row returned
69 if (! $row) {
70 exit;
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();
93 // [MIME]
94 if (isset($ct) && ! empty($ct)) {
95 $mime_type = $ct;
96 } else {
97 $mime_type = (isset($mime_map[$transform_key]['mimetype'])
98 ? str_replace('_', '/', $mime_map[$transform_key]['mimetype'])
99 : $default_ct)
100 . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
103 PMA_downloadHeader($cn, $mime_type);
105 if (! isset($resize)) {
106 echo $row[$transform_key];
107 } else {
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;
125 } else {
126 $destWidth = $newWidth;
127 $destHeight = $srcHeight/$ratioWidth;
130 if ($resize) {
131 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
134 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0,
135 // $destWidth, $destHeight, $srcWidth, $srcHeight);
136 // better quality but slower:
137 ImageCopyResampled(
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);