Documentation TYPO3 par Ameos

transformation_wrapper.php

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


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6