Documentation TYPO3 par Ameos

transformation_wrapper.php

00001 <?php
00002 /* $Id: transformation_wrapper.php,v 2.7 2004/08/21 13:41:41 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 $is_transformation_wrapper = true;
00006 
00010 require_once('./libraries/grab_globals.lib.php');
00011 
00015 require_once('./libraries/common.lib.php');
00016 require_once('./libraries/relation.lib.php'); // foreign keys
00017 require_once('./libraries/transformations.lib.php'); // Transformations
00018 $cfgRelation = PMA_getRelationsParam();
00019 
00023 require_once('./libraries/db_table_exists.lib.php');
00024 
00025 
00029 PMA_DBI_select_db($db);
00030 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), NULL, PMA_DBI_QUERY_STORE);
00031 if (isset($primary_key)) {
00032     $result      = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', NULL, PMA_DBI_QUERY_STORE);
00033     $row         = PMA_DBI_fetch_assoc($result);
00034 } else {
00035     $result      = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', NULL, PMA_DBI_QUERY_STORE);
00036     $row         = PMA_DBI_fetch_assoc($result);
00037 }
00038 
00039 // No row returned
00040 if (!$row) {
00041     exit;
00042 } // end if (no record returned)
00043 
00044 $default_ct = 'application/octet-stream';
00045 
00046 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
00047     $mime_map = PMA_getMime($db, $table);
00048     $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
00049 
00050     foreach ($mime_options AS $key => $option) {
00051         if (substr($option, 0, 10) == '; charset=') {
00052             $mime_options['charset'] = $option;
00053         }
00054     }
00055 }
00056 
00057 // garvin: For re-usability, moved http-headers and stylesheets
00058 // to a seperate file. It can now be included by header.inc.php,
00059 // queryframe.php, querywindow.php.
00060 
00061 require_once('./libraries/header_http.inc.php');
00062 // [MIME]
00063 if (isset($ct) && !empty($ct)) {
00064     $content_type = 'Content-Type: ' . urldecode($ct);
00065 } else {
00066     $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'] : '');
00067 }
00068 
00069 if (isset($cn) && !empty($cn)) {
00070     $content_type .= "\n" . 'Content-Disposition: attachment; filename=' . urldecode($cn);
00071 }
00072 
00073 header($content_type);
00074 
00075 if (!isset($resize)) {
00076     echo $row[urldecode($transform_key)];
00077 } else {
00078     // if image_*__inline.inc.php finds that we can resize,
00079     // it sets $resize to jpeg or png
00080 
00081     $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
00082     $srcWidth = ImageSX( $srcImage );
00083     $srcHeight = ImageSY( $srcImage );
00084 
00085     // Check to see if the width > height or if width < height
00086     // if so adjust accordingly to make sure the image
00087     // stays smaller then the $newWidth and $newHeight
00088 
00089     $ratioWidth = $srcWidth/$newWidth;
00090     $ratioHeight = $srcHeight/$newHeight;
00091 
00092     if ($ratioWidth < $ratioHeight){
00093         $destWidth = $srcWidth/$ratioHeight;
00094         $destHeight = $newHeight;
00095     }else{
00096         $destWidth = $newWidth;
00097         $destHeight = $srcHeight/$ratioWidth;
00098     }
00099 
00100     if ($resize) {
00101         $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
00102     }
00103 
00104 //    ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
00105 // better quality but slower:
00106     ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
00107 
00108     if ($resize == 'jpeg') {
00109         ImageJPEG( $destImage,'',75 );
00110     }
00111     if ($resize == 'png') {
00112         ImagePNG( $destImage);
00113     }
00114     ImageDestroy( $srcImage );
00115     ImageDestroy( $destImage );
00116 }
00117 
00121 if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
00122     @PMA_DBI_close($GLOBALS['dbh']);
00123 }
00124 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
00125     @PMA_DBI_close($GLOBALS['userlink']);
00126 }
00127 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6