Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / transformation_wrapper.php
blob0b87b43c25c7f2c2b3ec9886f794adb0d8add9cb
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 * Get the list of the fields of the current table
29 PMA_DBI_select_db($db);
30 if (isset($where_clause)) {
31 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE);
32 $row = PMA_DBI_fetch_assoc($result);
33 } else {
34 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
35 $row = PMA_DBI_fetch_assoc($result);
38 // No row returned
39 if (!$row) {
40 exit;
41 } // end if (no record returned)
43 $default_ct = 'application/octet-stream';
45 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
46 $mime_map = PMA_getMime($db, $table);
47 $mime_options = PMA_transformation_getOptions((isset($mime_map[$transform_key]['transformation_options']) ? $mime_map[$transform_key]['transformation_options'] : ''));
49 foreach ($mime_options AS $key => $option) {
50 if (substr($option, 0, 10) == '; charset=') {
51 $mime_options['charset'] = $option;
56 // For re-usability, moved http-headers and stylesheets
57 // to a seperate file. It can now be included by libraries/header.inc.php,
58 // querywindow.php.
60 require_once './libraries/header_http.inc.php';
61 // [MIME]
62 if (isset($ct) && !empty($ct)) {
63 $mime_type = $ct;
64 } else {
65 $mime_type = (isset($mime_map[$transform_key]['mimetype']) ? str_replace('_', '/', $mime_map[$transform_key]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
68 PMA_download_header($cn, $mime_type);
70 if (! isset($resize)) {
71 echo $row[$transform_key];
72 } else {
73 // if image_*__inline.inc.php finds that we can resize,
74 // it sets $resize to jpeg or png
76 $srcImage = imagecreatefromstring($row[$transform_key]);
77 $srcWidth = ImageSX($srcImage);
78 $srcHeight = ImageSY($srcImage);
80 // Check to see if the width > height or if width < height
81 // if so adjust accordingly to make sure the image
82 // stays smaller then the $newWidth and $newHeight
84 $ratioWidth = $srcWidth/$newWidth;
85 $ratioHeight = $srcHeight/$newHeight;
87 if ($ratioWidth < $ratioHeight) {
88 $destWidth = $srcWidth/$ratioHeight;
89 $destHeight = $newHeight;
90 } else {
91 $destWidth = $newWidth;
92 $destHeight = $srcHeight/$ratioWidth;
95 if ($resize) {
96 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
99 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
100 // better quality but slower:
101 ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
103 if ($resize == 'jpeg') {
104 ImageJPEG($destImage, '', 75);
106 if ($resize == 'png') {
107 ImagePNG($destImage);
109 ImageDestroy($srcImage);
110 ImageDestroy($destImage);