Update po files to match current sources
[phpmyadmin/ammar_yasir.git] / transformation_wrapper.php
blob3699dd09183bcc8f8b881c938badf8040f896eee
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 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
31 if (isset($where_clause)) {
32 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE);
33 $row = PMA_DBI_fetch_assoc($result);
34 } else {
35 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
36 $row = PMA_DBI_fetch_assoc($result);
39 // No row returned
40 if (!$row) {
41 exit;
42 } // end if (no record returned)
44 $default_ct = 'application/octet-stream';
46 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
47 $mime_map = PMA_getMime($db, $table);
48 $mime_options = PMA_transformation_getOptions((isset($mime_map[$transform_key]['transformation_options']) ? $mime_map[$transform_key]['transformation_options'] : ''));
50 foreach ($mime_options AS $key => $option) {
51 if (substr($option, 0, 10) == '; charset=') {
52 $mime_options['charset'] = $option;
57 // For re-usability, moved http-headers and stylesheets
58 // to a seperate file. It can now be included by libraries/header.inc.php,
59 // querywindow.php.
61 require_once './libraries/header_http.inc.php';
62 // [MIME]
63 if (isset($ct) && !empty($ct)) {
64 $content_type = 'Content-Type: ' . $ct;
65 } else {
66 $content_type = 'Content-Type: ' . (isset($mime_map[$transform_key]['mimetype']) ? str_replace('_', '/', $mime_map[$transform_key]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
68 header($content_type);
70 if (isset($cn) && !empty($cn)) {
71 header('Content-Disposition: attachment; filename=' . $cn);
74 if (!isset($resize)) {
75 echo $row[$transform_key];
76 } else {
77 // if image_*__inline.inc.php finds that we can resize,
78 // it sets $resize to jpeg or png
80 $srcImage = imagecreatefromstring($row[$transform_key]);
81 $srcWidth = ImageSX($srcImage);
82 $srcHeight = ImageSY($srcImage);
84 // Check to see if the width > height or if width < height
85 // if so adjust accordingly to make sure the image
86 // stays smaller then the $newWidth and $newHeight
88 $ratioWidth = $srcWidth/$newWidth;
89 $ratioHeight = $srcHeight/$newHeight;
91 if ($ratioWidth < $ratioHeight){
92 $destWidth = $srcWidth/$ratioHeight;
93 $destHeight = $newHeight;
94 } else {
95 $destWidth = $newWidth;
96 $destHeight = $srcHeight/$ratioWidth;
99 if ($resize) {
100 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
103 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
104 // better quality but slower:
105 ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
107 if ($resize == 'jpeg') {
108 ImageJPEG($destImage, '', 75);
110 if ($resize == 'png') {
111 ImagePNG($destImage);
113 ImageDestroy($srcImage);
114 ImageDestroy($destImage);