MediaWiki
REL1_22
|
00001 <?php 00033 class JpegHandler extends ExifBitmapHandler { 00034 00035 function getMetadata( $image, $filename ) { 00036 try { 00037 $meta = BitmapMetadataHandler::Jpeg( $filename ); 00038 if ( !is_array( $meta ) ) { 00039 // This should never happen, but doesn't hurt to be paranoid. 00040 throw new MWException( 'Metadata array is not an array' ); 00041 } 00042 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); 00043 return serialize( $meta ); 00044 } 00045 catch ( MWException $e ) { 00046 // BitmapMetadataHandler throws an exception in certain exceptional cases like if file does not exist. 00047 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" ); 00048 00049 /* This used to use 0 (ExifBitmapHandler::OLD_BROKEN_FILE) for the cases 00050 * * No metadata in the file 00051 * * Something is broken in the file. 00052 * However, if the metadata support gets expanded then you can't tell if the 0 is from 00053 * a broken file, or just no props found. A broken file is likely to stay broken, but 00054 * a file which had no props could have props once the metadata support is improved. 00055 * Thus switch to using -1 to denote only a broken file, and use an array with only 00056 * MEDIAWIKI_EXIF_VERSION to denote no props. 00057 */ 00058 return ExifBitmapHandler::BROKEN_FILE; 00059 } 00060 } 00061 00069 public function rotate( $file, $params ) { 00070 global $wgJpegTran; 00071 00072 $rotation = ( $params['rotation'] + $this->getRotation( $file ) ) % 360; 00073 00074 if ( $wgJpegTran && is_file( $wgJpegTran ) ) { 00075 $cmd = wfEscapeShellArg( $wgJpegTran ) . 00076 " -rotate " . wfEscapeShellArg( $rotation ) . 00077 " -outfile " . wfEscapeShellArg( $params['dstPath'] ) . 00078 " " . wfEscapeShellArg( $params['srcPath'] ); 00079 wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" ); 00080 wfProfileIn( 'jpegtran' ); 00081 $retval = 0; 00082 $err = wfShellExecWithStderr( $cmd, $retval, $env ); 00083 wfProfileOut( 'jpegtran' ); 00084 if ( $retval !== 0 ) { 00085 $this->logErrorForExternalProcess( $retval, $err, $cmd ); 00086 return new MediaTransformError( 'thumbnail_error', 0, 0, $err ); 00087 } 00088 return false; 00089 } else { 00090 return parent::rotate( $file, $params ); 00091 } 00092 } 00093 00094 }