|
MediaWiki
REL1_23
|
00001 <?php 00033 class JpegHandler extends ExifBitmapHandler { 00034 function getMetadata( $image, $filename ) { 00035 try { 00036 $meta = BitmapMetadataHandler::Jpeg( $filename ); 00037 if ( !is_array( $meta ) ) { 00038 // This should never happen, but doesn't hurt to be paranoid. 00039 throw new MWException( 'Metadata array is not an array' ); 00040 } 00041 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); 00042 00043 return serialize( $meta ); 00044 } catch ( MWException $e ) { 00045 // BitmapMetadataHandler throws an exception in certain exceptional 00046 // 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 00059 return ExifBitmapHandler::BROKEN_FILE; 00060 } 00061 } 00062 00070 public function rotate( $file, $params ) { 00071 global $wgJpegTran; 00072 00073 $rotation = ( $params['rotation'] + $this->getRotation( $file ) ) % 360; 00074 00075 if ( $wgJpegTran && is_file( $wgJpegTran ) ) { 00076 $cmd = wfEscapeShellArg( $wgJpegTran ) . 00077 " -rotate " . wfEscapeShellArg( $rotation ) . 00078 " -outfile " . wfEscapeShellArg( $params['dstPath'] ) . 00079 " " . wfEscapeShellArg( $params['srcPath'] ); 00080 wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" ); 00081 wfProfileIn( 'jpegtran' ); 00082 $retval = 0; 00083 $err = wfShellExecWithStderr( $cmd, $retval ); 00084 wfProfileOut( 'jpegtran' ); 00085 if ( $retval !== 0 ) { 00086 $this->logErrorForExternalProcess( $retval, $err, $cmd ); 00087 00088 return new MediaTransformError( 'thumbnail_error', 0, 0, $err ); 00089 } 00090 00091 return false; 00092 } else { 00093 return parent::rotate( $file, $params ); 00094 } 00095 } 00096 }