patch #2520747 [core] E_DEPRECATED compatibility for PHP 5.3
[phpmyadmin/crack.git] / transformation_wrapper.php
blobd79e89de5a9a356bf13efe5365360d10fd80c404
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
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/relation.lib.php'; // foreign keys
19 require_once './libraries/transformations.lib.php'; // Transformations
20 $cfgRelation = PMA_getRelationsParam();
22 /**
23 * Ensures db and table are valid, else moves to the "parent" script
25 require_once './libraries/db_table_exists.lib.php';
28 /**
29 * Get the list of the fields of the current table
31 PMA_DBI_select_db($db);
32 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
33 if (isset($primary_key)) {
34 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', null, PMA_DBI_QUERY_STORE);
35 $row = PMA_DBI_fetch_assoc($result);
36 } else {
37 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
38 $row = PMA_DBI_fetch_assoc($result);
41 // No row returned
42 if (!$row) {
43 exit;
44 } // end if (no record returned)
46 $default_ct = 'application/octet-stream';
48 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
49 $mime_map = PMA_getMime($db, $table);
50 $mime_options = PMA_transformation_getOptions((isset($mime_map[$transform_key]['transformation_options']) ? $mime_map[$transform_key]['transformation_options'] : ''));
52 foreach ($mime_options AS $key => $option) {
53 if (substr($option, 0, 10) == '; charset=') {
54 $mime_options['charset'] = $option;
59 // garvin: For re-usability, moved http-headers and stylesheets
60 // to a seperate file. It can now be included by libraries/header.inc.php,
61 // querywindow.php.
63 require_once './libraries/header_http.inc.php';
64 // [MIME]
65 if (isset($ct) && !empty($ct)) {
66 $content_type = 'Content-Type: ' . $ct;
67 } else {
68 $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'] : '');
70 header($content_type);
72 if (isset($cn) && !empty($cn)) {
73 header('Content-Disposition: attachment; filename=' . $cn);
76 if (!isset($resize)) {
77 echo $row[$transform_key];
78 } else {
79 // if image_*__inline.inc.php finds that we can resize,
80 // it sets $resize to jpeg or png
82 $srcImage = imagecreatefromstring($row[$transform_key]);
83 $srcWidth = ImageSX($srcImage);
84 $srcHeight = ImageSY($srcImage);
86 // Check to see if the width > height or if width < height
87 // if so adjust accordingly to make sure the image
88 // stays smaller then the $newWidth and $newHeight
90 $ratioWidth = $srcWidth/$newWidth;
91 $ratioHeight = $srcHeight/$newHeight;
93 if ($ratioWidth < $ratioHeight){
94 $destWidth = $srcWidth/$ratioHeight;
95 $destHeight = $newHeight;
96 } else {
97 $destWidth = $newWidth;
98 $destHeight = $srcHeight/$ratioWidth;
101 if ($resize) {
102 $destImage = ImageCreateTrueColor($destWidth, $destHeight);
105 // ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
106 // better quality but slower:
107 ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
109 if ($resize == 'jpeg') {
110 ImageJPEG($destImage, '', 75);
112 if ($resize == 'png') {
113 ImagePNG($destImage);
115 ImageDestroy($srcImage);
116 ImageDestroy($destImage);