Merge "tests: beginning of tests for DjVu files"
[lhc/web/wiklou.git] / includes / media / Tiff.php
1 <?php
2 /**
3 * Handler for Tiff images.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Media
22 */
23
24 /**
25 * Handler for Tiff images.
26 *
27 * @ingroup Media
28 */
29 class TiffHandler extends ExifBitmapHandler {
30 /**
31 * Conversion to PNG for inline display can be disabled here...
32 * Note scaling should work with ImageMagick, but may not with GD scaling.
33 *
34 * Files pulled from an another MediaWiki instance via ForeignAPIRepo /
35 * InstantCommons will have thumbnails managed from the remote instance,
36 * so we can skip this check.
37 *
38 * @param File $file
39 * @return bool
40 */
41 function canRender( $file ) {
42 global $wgTiffThumbnailType;
43
44 return (bool)$wgTiffThumbnailType
45 || $file->getRepo() instanceof ForeignAPIRepo;
46 }
47
48 /**
49 * Browsers don't support TIFF inline generally...
50 * For inline display, we need to convert to PNG.
51 *
52 * @param File $file
53 * @return bool
54 */
55 function mustRender( $file ) {
56 return true;
57 }
58
59 /**
60 * @param string $ext
61 * @param string $mime
62 * @param array $params
63 * @return bool
64 */
65 function getThumbType( $ext, $mime, $params = null ) {
66 global $wgTiffThumbnailType;
67
68 return $wgTiffThumbnailType;
69 }
70
71 /**
72 * @param File $image
73 * @param string $filename
74 * @throws MWException
75 * @return string
76 */
77 function getMetadata( $image, $filename ) {
78 global $wgShowEXIF;
79 if ( $wgShowEXIF ) {
80 try {
81 $meta = BitmapMetadataHandler::Tiff( $filename );
82 if ( !is_array( $meta ) ) {
83 // This should never happen, but doesn't hurt to be paranoid.
84 throw new MWException( 'Metadata array is not an array' );
85 }
86 $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
87
88 return serialize( $meta );
89 } catch ( MWException $e ) {
90 // BitmapMetadataHandler throws an exception in certain exceptional
91 // cases like if file does not exist.
92 wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
93
94 return ExifBitmapHandler::BROKEN_FILE;
95 }
96 } else {
97 return '';
98 }
99 }
100 }