Allow to configure how often space is added (RFE #1440384).
[phpmyadmin/last10db.git] / transformation_wrapper.php
blobda1325a3584fe241b3b2ab926e3fe2b04d629af0
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 define('IS_TRANSFORMATION_WRAPPER', true);
7 /**
8 * Gets a core script and starts output buffering work
9 */
10 require_once('./libraries/common.lib.php');
11 require_once('./libraries/relation.lib.php'); // foreign keys
12 require_once('./libraries/transformations.lib.php'); // Transformations
13 $cfgRelation = PMA_getRelationsParam();
15 /**
16 * Ensures db and table are valid, else moves to the "parent" script
18 require_once('./libraries/db_table_exists.lib.php');
21 /**
22 * Get the list of the fields of the current table
24 PMA_DBI_select_db($db);
25 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
26 if (isset($primary_key)) {
27 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', null, PMA_DBI_QUERY_STORE);
28 $row = PMA_DBI_fetch_assoc($result);
29 } else {
30 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
31 $row = PMA_DBI_fetch_assoc($result);
34 // No row returned
35 if (!$row) {
36 exit;
37 } // end if (no record returned)
39 $default_ct = 'application/octet-stream';
41 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
42 $mime_map = PMA_getMime($db, $table);
43 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
45 foreach ($mime_options AS $key => $option) {
46 if (substr($option, 0, 10) == '; charset=') {
47 $mime_options['charset'] = $option;
52 // garvin: For re-usability, moved http-headers and stylesheets
53 // to a seperate file. It can now be included by libraries/header.inc.php,
54 // querywindow.php.
56 require_once('./libraries/header_http.inc.php');
57 // [MIME]
58 if (isset($ct) && !empty($ct)) {
59 $content_type = 'Content-Type: ' . urldecode($ct);
60 } else {
61 $content_type = 'Content-Type: ' . (isset($mime_map[urldecode($transform_key)]['mimetype']) ? str_replace('_', '/', $mime_map[urldecode($transform_key)]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
64 if (isset($cn) && !empty($cn)) {
65 $content_type .= "\n" . 'Content-Disposition: attachment; filename=' . urldecode($cn);
68 header($content_type);
70 if (!isset($resize)) {
71 echo $row[urldecode($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[urldecode($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 );
114 * Close MySql non-persistent connections
116 if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) {
117 @PMA_DBI_close($GLOBALS['controllink']);
119 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
120 @PMA_DBI_close($GLOBALS['userlink']);