7 * Class to represent an image
9 * Provides methods to retrieve paths (physical, logical, URL),
10 * to generate thumbnails or for uploading.
18 var $name, # name of the image
19 $imagePath, # Path of the image
21 $title, # Title object for this image. Initialized when needed.
22 $fileExists, # does the image file exist on disk?
23 $fromSharedDirectory, # load this image from $wgSharedUploadDirectory
24 $historyLine, # Number of line to return by nextHistoryLine()
25 $historyRes, # result of the query for the image's history
28 $bits, # --- returned by getimagesize, see http://de3.php.net/manual/en/function.getimagesize.php
36 * Create an Image object from an image name
38 * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
41 function Image( $name )
44 global $wgUseSharedUploads, $wgUseLatin1, $wgSharedLatin1, $wgLang;
47 $this->title
= Title
::makeTitleSafe( NS_IMAGE
, $this->name
);
48 $this->fromSharedDirectory
= false;
49 $this->imagePath
= $this->getFullPath();
50 $this->fileExists
= file_exists( $this->imagePath
);
52 # If the file is not found, and a shared upload directory
53 # like the Wikimedia Commons is used, look for it there.
54 if (!$this->fileExists
&& $wgUseSharedUploads) {
56 # In case we're on a wgCapitalLinks=false wiki, we
57 # capitalize the first letter of the filename before
58 # looking it up in the shared repository.
59 $this->name
= $wgLang->ucfirst($name);
61 # Encode the filename if we're on a Latin1 wiki and the
62 # shared repository is UTF-8
63 if($wgUseLatin1 && !$wgSharedLatin1) {
64 $this->name
= utf8_encode($name);
67 $this->imagePath
= $this->getFullPath(true);
68 $this->fileExists
= file_exists( $this->imagePath
);
69 $this->fromSharedDirectory
= true;
73 if($this->fileExists
) {
74 $this->url
= $this->wfImageUrl( $this->name
, $this->fromSharedDirectory
);
79 $n = strrpos( $name, '.' );
80 $this->extension
= strtolower( $n ?
substr( $name, $n +
1 ) : '' );
83 if ( $this->fileExists
)
85 if( $this->extension
== 'svg' ) {
86 @$gis = getSVGsize( $this->imagePath
);
88 @$gis = getimagesize( $this->imagePath
);
90 if( $gis !== false ) {
91 $this->width
= $gis[0];
92 $this->height
= $gis[1];
93 $this->type
= $gis[2];
94 $this->attr
= $gis[3];
95 if ( isset( $gis['bits'] ) ) {
96 $this->bits
= $gis['bits'];
102 $this->historyLine
= 0;
108 * Create a new image object from a title object.
110 * @param Title $nt Title object. Must be from namespace "image"
113 function newFromTitle( $nt )
115 $img = new Image( $nt->getDBKey() );
121 * Return the name of this image
130 * Return the associated title object
139 * Return the URL of the image file
147 function getViewURL() {
148 if( $this->mustRender() ) {
149 return $this->createThumb( $this->getWidth() );
151 return $this->getURL();
156 * Return the image path of the image in the
157 * local file system as an absolute path
160 function getImagePath()
162 return $this->imagePath
;
166 * Return the width of the image
168 * Returns -1 if the file specified is not a known image type
177 * Return the height of the image
179 * Returns -1 if the file specified is not a known image type
184 return $this->height
;
188 * Return the size of the image file, in bytes
193 $st = stat( $this->getImagePath() );
202 * Return the type of the image
216 * Return the escapeLocalURL of this image
219 function getEscapeLocalURL()
221 return $this->title
->escapeLocalURL();
225 * Return the escapeFullURL of this image
228 function getEscapeFullURL()
230 return $this->title
->escapeFullURL();
234 * Return the URL of an image, provided its name.
236 * @param string $name Name of the image, without the leading "Image:"
237 * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
240 function wfImageUrl( $name, $fromSharedDirectory = false )
242 global $wgUploadPath,$wgUploadBaseUrl,$wgSharedUploadPath;
243 if($fromSharedDirectory) {
245 $path = $wgSharedUploadPath;
247 $base = $wgUploadBaseUrl;
248 $path = $wgUploadPath;
250 $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$name}";
251 return wfUrlencode( $url );
255 * Returns true iff the image file exists on disk.
261 return $this->fileExists
;
268 function thumbUrl( $width, $subdir='thumb') {
269 global $wgUploadPath, $wgUploadBaseUrl,
270 $wgSharedUploadPath,$wgSharedUploadDirectory,
271 $wgUseLatin1,$wgSharedLatin1;
272 $name = $this->thumbName( $width );
273 if($this->fromSharedDirectory
) {
275 $path = $wgSharedUploadPath;
276 if($wgUseLatin1 && !$wgSharedLatin1) {
277 $name=utf8_encode($name);
280 $base = $wgUploadBaseUrl;
281 $path = $wgUploadPath;
283 $url = "{$base}{$path}/{$subdir}" .
284 wfGetHashPath($name, $this->fromSharedDirectory
)
286 return wfUrlencode($url);
290 * Return the file name of a thumbnail of the specified width
292 * @param integer $width Width of the thumbnail image
293 * @param boolean $shared Does the thumbnail come from the shared repository?
296 function thumbName( $width, $shared=false ) {
297 global $wgUseLatin1,$wgSharedLatin1;
298 $thumb = $width."px-".$this->name
;
299 if( $this->extension
== 'svg' ) {
300 # Rasterize SVG vector images to PNG
303 if( $shared && $wgUseLatin1 && !$wgSharedLatin1) {
304 $thumb=utf8_encode($thumb);
310 * Create a thumbnail of the image having the specified width/height.
311 * The thumbnail will not be created if the width is larger than the
312 * image's width. Let the browser do the scaling in this case.
313 * The thumbnail is stored on disk and is only computed if the thumbnail
314 * file does not exist OR if it is older than the image.
317 * Keeps aspect ratio of original image. If both width and height are
318 * specified, the generated image will be no bigger than width x height,
319 * and will also have correct aspect ratio.
321 * @param integer $width maximum width of the generated thumbnail
322 * @param integer $height maximum height of the image (optional)
325 function createThumb( $width, $height=-1 ) {
326 $thumb = $this->getThumbnail( $width, $height );
327 if( is_null( $thumb ) ) return '';
328 return $thumb->getUrl();
332 * As createThumb, but returns a ThumbnailImage object. This can
333 * provide access to the actual file, the real size of the thumb,
334 * and can produce a convenient <img> tag for you.
336 * @param integer $width maximum width of the generated thumbnail
337 * @param integer $height maximum height of the image (optional)
338 * @return ThumbnailImage
341 function &getThumbnail( $width, $height=-1 ) {
342 if ( $height == -1 ) {
343 return $this->renderThumb( $width );
345 if ( $width < $this->width
) {
346 $thumbheight = $this->height
* $width / $this->width
;
347 $thumbwidth = $width;
349 $thumbheight = $this->height
;
350 $thumbwidth = $this->width
;
352 if ( $thumbheight > $height ) {
353 $thumbwidth = $thumbwidth * $height / $thumbheight;
354 $thumbheight = $height;
356 $thumb = $this->renderThumb( $thumbwidth );
357 if( is_null( $thumb ) ) {
358 $thumb = $this->iconThumb();
364 * @return ThumbnailImage
366 function iconThumb() {
367 global $wgStylePath, $wgStyleDirectory;
369 $try = array( 'fileicon-' . $this->extension
. '.png', 'fileicon.png' );
370 foreach( $try as $icon ) {
371 $path = '/common/images/' . $icon;
372 $filepath = $wgStyleDirectory . $path;
373 if( file_exists( $filepath ) ) {
374 return new ThumbnailImage( $filepath, $wgStylePath . $path );
381 * Create a thumbnail of the image having the specified width.
382 * The thumbnail will not be created if the width is larger than the
383 * image's width. Let the browser do the scaling in this case.
384 * The thumbnail is stored on disk and is only computed if the thumbnail
385 * file does not exist OR if it is older than the image.
386 * Returns an object which can return the pathname, URL, and physical
387 * pixel size of the thumbnail -- or null on failure.
389 * @return ThumbnailImage
392 function /* private */ renderThumb( $width ) {
393 global $wgImageMagickConvertCommand;
394 global $wgUseImageMagick;
395 global $wgUseSquid, $wgInternalServer;
397 $width = IntVal( $width );
399 $thumbName = $this->thumbName( $width, $this->fromSharedDirectory
);
400 $thumbPath = wfImageThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory
).'/'.$thumbName;
401 $thumbUrl = $this->thumbUrl( $width );
402 #wfDebug ( "Render name: $thumbName path: $thumbPath url: $thumbUrl\n");
403 if ( ! $this->exists() )
405 # If there is no image, there will be no thumbnail
409 # Sanity check $width
415 if( $width > $this->width
&& !$this->mustRender() ) {
416 # Don't make an image bigger than the source
417 return new ThumbnailImage( $this->getImagePath(), $this->getViewURL() );
420 if ( (! file_exists( $thumbPath ) ) ||
( filemtime($thumbPath) < filemtime($this->imagePath
) ) ) {
421 if( $this->extension
== 'svg' ) {
422 global $wgSVGConverters, $wgSVGConverter;
423 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
424 global $wgSVGConverterPath;
426 array( '$path/', '$width', '$input', '$output' ),
427 array( $wgSVGConverterPath,
429 escapeshellarg( $this->imagePath
),
430 escapeshellarg( $thumbPath ) ),
431 $wgSVGConverters[$wgSVGConverter] );
432 $conv = shell_exec( $cmd );
436 } elseif ( $wgUseImageMagick ) {
438 # Specify white background color, will be used for transparent images
439 # in Internet Explorer/Windows instead of default black.
440 $cmd = $wgImageMagickConvertCommand .
441 " -quality 85 -background white -geometry {$width} ".
442 escapeshellarg($this->imagePath
) . " " .
443 escapeshellarg($thumbPath);
444 $conv = shell_exec( $cmd );
446 # Use PHP's builtin GD library functions.
448 # First find out what kind of file this is, and select the correct
449 # input routine for this.
453 switch( $this->type
) {
455 $src_image = imagecreatefromgif( $this->imagePath
);
458 $src_image = imagecreatefromjpeg( $this->imagePath
);
462 $src_image = imagecreatefrompng( $this->imagePath
);
463 $truecolor = ( $this->bits
> 8 );
465 case 15: # WBMP for WML
466 $src_image = imagecreatefromwbmp( $this->imagePath
);
469 $src_image = imagecreatefromxbm( $this->imagePath
);
472 return 'Image type not supported';
475 $height = floor( $this->height
* ( $width/$this->width
) );
477 $dst_image = imagecreatetruecolor( $width, $height );
479 $dst_image = imagecreate( $width, $height );
481 imagecopyresampled( $dst_image, $src_image,
483 $width, $height, $this->width
, $this->height
);
484 switch( $this->type
) {
489 #$thumbUrl .= ".png";
490 #$thumbPath .= ".png";
491 imagepng( $dst_image, $thumbPath );
494 #$thumbUrl .= ".jpg";
495 #$thumbPath .= ".jpg";
496 imageinterlace( $dst_image );
497 imagejpeg( $dst_image, $thumbPath, 95 );
502 imagedestroy( $dst_image );
503 imagedestroy( $src_image );
506 # Check for zero-sized thumbnails. Those can be generated when
507 # no disk space is available or some other error occurs
509 if( file_exists( $thumbPath ) ) {
510 $thumbstat = stat( $thumbPath );
511 if( $thumbstat['size'] == 0 ) {
512 unlink( $thumbPath );
517 # This has to be done after the image is updated and present for all machines on NFS,
518 # or else the old version might be stored into the squid again
521 $wgInternalServer.$thumbUrl
523 wfPurgeSquidServers($urlArr);
526 return new ThumbnailImage( $thumbPath, $thumbUrl );
527 } // END OF function createThumb
530 * Return the image history of this image, line by line.
531 * starts with current version, then old versions.
532 * uses $this->historyLine to check which line to return:
533 * 0 return line for current version
534 * 1 query for old versions, return first one
535 * 2, ... return next old version from above query
539 function nextHistoryLine()
541 $fname = 'Image::nextHistoryLine()';
542 $dbr =& wfGetDB( DB_SLAVE
);
543 if ( $this->historyLine
== 0 ) {// called for the first time, return line from cur
544 $this->historyRes
= $dbr->select( 'image',
545 array( 'img_size','img_description','img_user','img_user_text','img_timestamp', "'' AS oi_archive_name" ),
546 array( 'img_name' => $this->title
->getDBkey() ),
549 if ( 0 == wfNumRows( $this->historyRes
) ) {
552 } else if ( $this->historyLine
== 1 ) {
553 $this->historyRes
= $dbr->select( 'oldimage',
554 array( 'oi_size AS img_size', 'oi_description AS img_description', 'oi_user AS img_user',
555 'oi_user_text AS img_user_text', 'oi_timestamp AS img_timestamp', 'oi_archive_name'
556 ), array( 'oi_name' => $this->title
->getDBkey() ), $fname, array( 'ORDER BY' => 'oi_timestamp DESC' )
559 $this->historyLine ++
;
561 return $dbr->fetchObject( $this->historyRes
);
565 * Reset the history pointer to the first element of the history
568 function resetHistory()
570 $this->historyLine
= 0;
574 * Return true if the file is of a type that can't be directly
575 * rendered by typical browsers and needs to be re-rasterized.
578 function mustRender() {
579 return ( $this->extension
== 'svg' );
583 * Return the full filesystem path to the file. Note that this does
584 * not mean that a file actually exists under that location.
586 * This path depends on whether directory hashing is active or not,
587 * i.e. whether the images are all found in the same directory,
588 * or in hashed paths like /images/3/3c.
591 * @param boolean $fromSharedDirectory Return the path to the file
592 * in a shared repository (see $wgUseSharedRepository and related
593 * options in DefaultSettings.php) instead of a local one.
596 function getFullPath( $fromSharedRepository = false )
598 global $wgUploadDirectory, $wgSharedUploadDirectory;
599 global $wgHashedUploadDirectory, $wgHashedSharedUploadDirectory;
601 $dir = $fromSharedRepository ?
$wgSharedUploadDirectory :
603 $ishashed = $fromSharedRepository ?
$wgHashedSharedUploadDirectory :
604 $wgHashedUploadDirectory;
606 $fullpath = $dir . wfGetHashPath($name) . $name;
615 * Returns the image directory of an image
616 * If the directory does not exist, it is created.
617 * The result is an absolute path.
619 * @param string $fname file name of the image file
622 function wfImageDir( $fname )
624 global $wgUploadDirectory, $wgHashedUploadDirectory;
626 if (!$wgHashedUploadDirectory) { return $wgUploadDirectory; }
628 $hash = md5( $fname );
629 $oldumask = umask(0);
630 $dest = $wgUploadDirectory . '/' . $hash{0};
631 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
632 $dest .= '/' . substr( $hash, 0, 2 );
633 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
640 * Returns the image directory of an image's thubnail
641 * If the directory does not exist, it is created.
642 * The result is an absolute path.
644 * @param string $fname file name of the thumbnail file, including file size prefix
645 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the thumbnail. Default is 'thumb'
646 * @param boolean $shared (optional) use the shared upload directory
649 function wfImageThumbDir( $fname , $subdir='thumb', $shared=false)
651 return wfImageArchiveDir( $fname, $subdir, $shared );
655 * Returns the image directory of an image's old version
656 * If the directory does not exist, it is created.
657 * The result is an absolute path.
659 * @param string $fname file name of the thumbnail file, including file size prefix
660 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the old version. Default is 'archive'
661 * @param boolean $shared (optional) use the shared upload directory (only relevant for other functions which call this one)
664 function wfImageArchiveDir( $fname , $subdir='archive', $shared=false )
666 global $wgUploadDirectory, $wgHashedUploadDirectory,
667 $wgSharedUploadDirectory, $wgHashedSharedUploadDirectory;
668 $dir = $shared ?
$wgSharedUploadDirectory : $wgUploadDirectory;
669 $hashdir = $shared ?
$wgHashedSharedUploadDirectory : $wgHashedUploadDirectory;
670 if (!$hashdir) { return $dir.'/'.$subdir; }
671 $hash = md5( $fname );
672 $oldumask = umask(0);
673 # Suppress warning messages here; if the file itself can't
674 # be written we'll worry about it then.
675 $archive = $dir.'/'.$subdir;
676 if ( ! is_dir( $archive ) ) { @mkdir
( $archive, 0777 ); }
677 $archive .= '/' . $hash{0};
678 if ( ! is_dir( $archive ) ) { @mkdir
( $archive, 0777 ); }
679 $archive .= '/' . substr( $hash, 0, 2 );
680 if ( ! is_dir( $archive ) ) { @mkdir
( $archive, 0777 ); }
688 * Return the hash path component of an image path (URL or filesystem),
689 * e.g. "/3/3c/", or just "/" if hashing is not used.
691 * @param $dbkey The filesystem / database name of the file
692 * @param $fromSharedDirectory Use the shared file repository? It may
693 * use different hash settings from the local one.
695 function wfGetHashPath ( $dbkey, $fromSharedDirectory = false ) {
696 global $wgHashedSharedUploadDirectory, $wgSharedUploadDirectory;
698 $ishashed = $fromSharedDirectory ?
$wgHashedSharedUploadDirectory :
699 $wgSharedUploadDirectory;
702 return '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . "/";
710 * Record an image upload in the upload log.
712 function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source = "" )
714 global $wgUser, $wgLang, $wgTitle, $wgOut, $wgDeferredUpdateList;
715 global $wgUseCopyrightUpload;
717 $fname = 'wfRecordUpload';
718 $dbw =& wfGetDB( DB_MASTER
);
720 # img_name must be unique
721 if ( !$dbw->indexUnique( 'image', 'img_name' ) && !$dbw->indexExists('image','PRIMARY') ) {
722 wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
726 $now = wfTimestampNow();
727 $won = wfInvertTimestamp( $now );
728 $size = IntVal( $size );
730 if ( $wgUseCopyrightUpload )
732 $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
733 '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
734 '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
736 else $textdesc = $desc ;
738 $now = wfTimestampNow();
739 $won = wfInvertTimestamp( $now );
741 # Test to see if the row exists using INSERT IGNORE
742 # This avoids race conditions by locking the row until the commit, and also
743 # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
744 $dbw->insert( 'image',
748 'img_timestamp' => $dbw->timestamp($now),
749 'img_description' => $desc,
750 'img_user' => $wgUser->getID(),
751 'img_user_text' => $wgUser->getName(),
754 $descTitle = Title
::makeTitleSafe( NS_IMAGE
, $name );
756 if ( $dbw->affectedRows() ) {
757 # Successfully inserted, this is a new image
758 $id = $descTitle->getArticleID();
761 $now = wfTimestampNow();
762 $won = wfInvertTimestamp( $now );
764 $text_old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
765 $dbw->insert( 'text',
767 'old_id' => $text_old_id,
768 'old_text' => $textdesc,
771 if ( is_null( $text_old_id ) ) $text_old_id = $dbw->insertId();
773 $page_page_id = $dbw->nextSequenceValue( 'page_page_id' );
774 $dbw->insert( 'page',
776 'page_id' => $page_page_id,
777 'page_namespace' => NS_IMAGE
,
778 'page_title' => $name,
779 'page_restrictions' => '',
781 'page_is_redirect' => 0,
783 'page_random' => 0.5,
784 'page_touched' => $now,
785 'page_latest' => $text_old_id ),
787 if ( is_null( $page_page_id ) ) $page_page_id = $dbw->insertId();
789 $dbw->insert( 'revision',
791 'rev_id' => $text_old_id,
792 'rev_page' => $page_page_id,
793 'rev_comment' => $desc,
794 'rev_user' => $wgUser->getID(),
795 'rev_user_text' => $wgUser->getName(),
796 'rev_timestamp' => $now,
797 'inverse_timestamp' => $won,
798 'rev_minor_edit' => 0 ),
801 RecentChange
::notifyNew( $now, $descTitle, 0, $wgUser, $desc );
803 $u = new SearchUpdate( $page_page_id, $name, $desc );
807 # Collision, this is an update of an image
808 # Get current image row for update
809 $s = $dbw->selectRow( 'image', array( 'img_name','img_size','img_timestamp','img_description',
810 'img_user','img_user_text' ), array( 'img_name' => $name ), $fname, 'FOR UPDATE' );
812 # Insert it into oldimage
813 $dbw->insert( 'oldimage',
815 'oi_name' => $s->img_name
,
816 'oi_archive_name' => $oldver,
817 'oi_size' => $s->img_size
,
818 'oi_timestamp' => $dbw->timestamp($s->img_timestamp
),
819 'oi_description' => $s->img_description
,
820 'oi_user' => $s->img_user
,
821 'oi_user_text' => $s->img_user_text
825 # Update the current image row
826 $dbw->update( 'image',
829 'img_timestamp' => $dbw->timestamp(),
830 'img_user' => $wgUser->getID(),
831 'img_user_text' => $wgUser->getName(),
832 'img_description' => $desc,
833 ), array( /* WHERE */
838 # Invalidate the cache for the description page
839 $descTitle->invalidateCache();
842 $log = new LogPage( 'upload' );
843 $log->addEntry( 'upload', $descTitle, $desc );
847 * Returns the image URL of an image's old version
849 * @param string $fname file name of the image file
850 * @param string $subdir (optional) subdirectory of the image upload directory that is used by the old version. Default is 'archive'
853 function wfImageArchiveUrl( $name, $subdir='archive' )
855 global $wgUploadPath, $wgHashedUploadDirectory;
857 if ($wgHashedUploadDirectory) {
858 $hash = md5( substr( $name, 15) );
859 $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' .
860 substr( $hash, 0, 2 ) . '/'.$name;
862 $url = $wgUploadPath.'/'.$subdir.'/'.$name;
864 return wfUrlencode($url);
868 * Return a rounded pixel equivalent for a labeled CSS/SVG length.
869 * http://www.w3.org/TR/SVG11/coords.html#UnitIdentifiers
871 * @param string $length
872 * @return int Length in pixels
874 function scaleSVGUnit( $length ) {
875 static $unitLength = array(
882 '' => 1.0, // "User units" pixels by default
883 '%' => 2.0, // Fake it!
885 if( preg_match( '/^(\d+)(em|ex|px|pt|pc|cm|mm|in|%|)$/', $length, $matches ) ) {
886 $length = FloatVal( $matches[1] );
888 return round( $length * $unitLength[$unit] );
891 return round( FloatVal( $length ) );
896 * Compatible with PHP getimagesize()
897 * @todo support gzipped SVGZ
898 * @todo check XML more carefully
899 * @todo sensible defaults
901 * @param string $filename
904 function getSVGsize( $filename ) {
908 // Read a chunk of the file
909 $f = fopen( $filename, "rt" );
910 if( !$f ) return false;
911 $chunk = fread( $f, 4096 );
914 // Uber-crappy hack! Run through a real XML parser.
915 if( !preg_match( '/<svg\s*([^>]*)\s*>/s', $chunk, $matches ) ) {
919 if( preg_match( '/\bwidth\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
920 $width = scaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
922 if( preg_match( '/\bheight\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
923 $height = scaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
926 return array( $width, $height, 'SVG',
927 "width=\"$width\" height=\"$height\"" );
932 * Wrapper class for thumbnail images
934 class ThumbnailImage
{
936 * @param string $path Filesystem path to the thumb
937 * @param string $url URL path to the thumb
940 function ThumbnailImage( $path, $url ) {
943 $size = @getimagesize
( $this->path
);
945 $this->width
= $size[0];
946 $this->height
= $size[1];
958 * Return HTML <img ... /> tag for the thumbnail, will include
959 * width and height attributes and a blank alt text (as required).
961 * You can set or override additional attributes by passing an
962 * associative array of name => data pairs. The data will be escaped
963 * for HTML output, so should be in plaintext.
965 * @param array $attribs
969 function toHtml( $attribs = array() ) {
970 $attribs['src'] = $this->url
;
971 $attribs['width'] = $this->width
;
972 $attribs['height'] = $this->height
;
973 if( !isset( $attribs['alt'] ) ) $attribs['alt'] = '';
976 foreach( $attribs as $name => $data ) {
977 $html .= $name . '="' . htmlspecialchars( $data ) . '" ';
984 * Return the size of the thumbnail file, in bytes
989 $st = stat( $this->path
);