(bug 737) only use the post-parse link placeholders within replaceInternalLinks().
[lhc/web/wiklou.git] / includes / Image.php
1 <?php
2 /**
3 * @package MediaWiki
4 * $Id$
5 */
6
7 /**
8 * Class to represent an image
9 *
10 * Provides methods to retrieve paths (physical, logical, URL),
11 * to generate thumbnails or for uploading.
12 * @package MediaWiki
13 */
14 class Image
15 {
16 /**#@+
17 * @access private
18 */
19 var $name, # name of the image
20 $imagePath, # Path of the image
21 $url, # Image URL
22 $title, # Title object for this image. Initialized when needed.
23 $fileExists, # does the image file exist on disk?
24 $historyLine, # Number of line to return by nextHistoryLine()
25 $historyRes, # result of the query for the image's history
26 $width, # \
27 $height, # |
28 $bits, # --- returned by getimagesize, see http://de3.php.net/manual/en/function.getimagesize.php
29 $type, # |
30 $attr; # /
31
32 /**#@-*/
33
34
35 /**
36 * Create an Image object from an image name
37 *
38 * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
39 * @access public
40 */
41 function Image( $name )
42 {
43 global $wgUploadDirectory,$wgHashedUploadDirectory;
44
45 $this->name = $name;
46 $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name );
47 //$this->imagePath = wfImagePath( $name );
48 if ($wgHashedUploadDirectory) {
49 $hash = md5( $this->title->getDBkey() );
50 $this->imagePath = $wgUploadDirectory . '/' . $hash{0} . '/' .
51 substr( $hash, 0, 2 ) . "/{$name}";
52 } else {
53 $this->imagePath = $wgUploadDirectory . '/' . $name;
54 }
55
56 $this->url = $this->wfImageUrl( $name );
57
58 $n = strrpos( $name, '.' );
59 $this->extension = strtolower( $n ? substr( $name, $n + 1 ) : '' );
60
61 if ( $this->fileExists = file_exists( $this->imagePath ) ) // Sic!, "=" is intended
62 {
63 if( $this->extension == 'svg' ) {
64 @$gis = getSVGsize( $this->imagePath );
65 } else {
66 @$gis = getimagesize( $this->imagePath );
67 }
68 if( $gis !== false ) {
69 $this->width = $gis[0];
70 $this->height = $gis[1];
71 $this->type = $gis[2];
72 $this->attr = $gis[3];
73 if ( isset( $gis['bits'] ) ) {
74 $this->bits = $gis['bits'];
75 } else {
76 $this->bits = 0;
77 }
78 }
79 }
80 $this->historyLine = 0;
81 }
82
83 /**
84 * Factory function
85 *
86 * Create a new image object from a title object.
87 *
88 * @param Title $nt Title object. Must be from namespace "image"
89 * @access public
90 */
91 function newFromTitle( $nt )
92 {
93 $img = new Image( $nt->getDBKey() );
94 $img->title = $nt;
95 return $img;
96 }
97
98 /**
99 * Return the name of this image
100 * @access public
101 */
102 function getName()
103 {
104 return $this->name;
105 }
106
107 /**
108 * Return the associated title object
109 * @access public
110 */
111 function getTitle()
112 {
113 return $this->title;
114 }
115
116 /**
117 * Return the URL of the image file
118 * @access public
119 */
120 function getURL()
121 {
122 return $this->url;
123 }
124
125 function getViewURL() {
126 if( $this->mustRender() ) {
127 return $this->createThumb( $this->getWidth() );
128 } else {
129 return $this->getURL();
130 }
131 }
132
133 /**
134 * Return the image path of the image in the
135 * local file system as an absolute path
136 * @access public
137 */
138 function getImagePath()
139 {
140 return $this->imagePath;
141 }
142
143 /**
144 * Return the width of the image
145 *
146 * Returns -1 if the file specified is not a known image type
147 * @access public
148 */
149 function getWidth()
150 {
151 return $this->width;
152 }
153
154 /**
155 * Return the height of the image
156 *
157 * Returns -1 if the file specified is not a known image type
158 * @access public
159 */
160 function getHeight()
161 {
162 return $this->height;
163 }
164
165 /**
166 * Return the size of the image file, in bytes
167 * @access public
168 */
169 function getSize()
170 {
171 $st = stat( $this->getImagePath() );
172 return $st['size'];
173 }
174
175 /**
176 * Return the type of the image
177 *
178 * - 1 GIF
179 * - 2 JPG
180 * - 3 PNG
181 * - 15 WBMP
182 * - 16 XBM
183 */
184 function getType()
185 {
186 return $this->type;
187 }
188
189 /**
190 * Return the escapeLocalURL of this image
191 * @access public
192 */
193 function getEscapeLocalURL()
194 {
195 return $this->title->escapeLocalURL();
196 }
197
198 /**
199 * Return the escapeFullURL of this image
200 * @access public
201 */
202 function getEscapeFullURL()
203 {
204 return $this->title->escapeFullURL();
205 }
206
207 /**
208 * Return the URL of an image, provided its name.
209 *
210 * @param string $name Name of the image, without the leading Image:
211 * @access public
212 */
213 function wfImageUrl( $name )
214 {
215 global $wgUploadPath,$wgUploadBaseUrl,$wgHashedUploadDirectory;
216 if ($wgHashedUploadDirectory) {
217 $hash = md5( $name );
218 $url = "{$wgUploadBaseUrl}{$wgUploadPath}/" . $hash{0} . "/" .
219 substr( $hash, 0, 2 ) . "/{$name}";
220 } else {
221 $url = "{$wgUploadBaseUrl}{$wgUploadPath}/{$name}";
222 }
223 return wfUrlencode( $url );
224 }
225
226 /**
227 * Returns true iff the image file exists on disk.
228 *
229 * @access public
230 */
231 function exists()
232 {
233 return $this->fileExists;
234 }
235
236 /**
237 *
238 * @access private
239 */
240 function thumbUrl( $width, $subdir='thumb' ) {
241 global $wgUploadPath,$wgHashedUploadDirectory;
242 $name = $this->thumbName( $width );
243 if ($wgHashedUploadDirectory) {
244 $hash = md5( $name );
245 $url = "{$wgUploadPath}/{$subdir}/" . $hash{0} . "/" .
246 substr( $hash, 0, 2 ) . "/{$name}";
247 } else {
248 $url = "{$wgUploadPath}/{$subdir}/{$name}";
249 }
250
251 return wfUrlencode($url);
252 }
253
254 /**
255 * Return the file name of a thumbnail of the specified width
256 *
257 * @param integer $width Width of the thumbnail image
258 * @access private
259 */
260 function thumbName( $width ) {
261 $thumb = $width."px-".$this->name;
262 if( $this->extension == 'svg' ) {
263 # Rasterize SVG vector images to PNG
264 $thumb .= '.png';
265 }
266 return $thumb;
267 }
268
269 /**
270 * Create a thumbnail of the image having the specified width/height.
271 * The thumbnail will not be created if the width is larger than the
272 * image's width. Let the browser do the scaling in this case.
273 * The thumbnail is stored on disk and is only computed if the thumbnail
274 * file does not exist OR if it is older than the image.
275 * Returns the URL.
276 *
277 * Keeps aspect ratio of original image. If both width and height are
278 * specified, the generated image will be no bigger than width x height,
279 * and will also have correct aspect ratio.
280 *
281 * @param integer $width maximum width of the generated thumbnail
282 * @param integer $height maximum height of the image (optional)
283 * @access public
284 */
285 function createThumb( $width, $height=-1 ) {
286 if ( $height == -1 ) {
287 return $this->renderThumb( $width );
288 }
289 if ( $width < $this->width ) {
290 $thumbheight = $this->height * $width / $this->width;
291 $thumbwidth = $width;
292 } else {
293 $thumbheight = $this->height;
294 $thumbwidth = $this->width;
295 }
296 if ( $thumbheight > $height ) {
297 $thumbwidth = $thumbwidth * $height / $thumbheight;
298 $thumbheight = $height;
299 }
300 return $this->renderThumb( $thumbwidth );
301 }
302
303 /**
304 * Create a thumbnail of the image having the specified width.
305 * The thumbnail will not be created if the width is larger than the
306 * image's width. Let the browser do the scaling in this case.
307 * The thumbnail is stored on disk and is only computed if the thumbnail
308 * file does not exist OR if it is older than the image.
309 * Returns the URL.
310 *
311 * @access private
312 */
313 function /* private */ renderThumb( $width ) {
314 global $wgUploadDirectory;
315 global $wgImageMagickConvertCommand;
316 global $wgUseImageMagick;
317 global $wgUseSquid, $wgInternalServer;
318
319 $width = IntVal( $width );
320
321 $thumbName = $this->thumbName( $width );
322 $thumbPath = wfImageThumbDir( $thumbName ).'/'.$thumbName;
323 $thumbUrl = $this->thumbUrl( $width );
324
325 if ( ! $this->exists() )
326 {
327 # If there is no image, there will be no thumbnail
328 return '';
329 }
330
331 # Sanity check $width
332 if( $width <= 0 ) {
333 # BZZZT
334 return '';
335 }
336
337 if( $width > $this->width && !$this->mustRender() ) {
338 # Don't make an image bigger than the source
339 return $this->getViewURL();
340 }
341
342 if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) {
343 if( $this->extension == 'svg' ) {
344 global $wgSVGConverters, $wgSVGConverter;
345 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
346 global $wgSVGConverterPath;
347 $cmd = str_replace(
348 array( '$path/', '$width', '$input', '$output' ),
349 array( $wgSVGConverterPath,
350 $width,
351 escapeshellarg( $this->imagePath ),
352 escapeshellarg( $thumbPath ) ),
353 $wgSVGConverters[$wgSVGConverter] );
354 $conv = shell_exec( $cmd );
355 } else {
356 $conv = false;
357 }
358 } elseif ( $wgUseImageMagick ) {
359 # use ImageMagick
360 # Specify white background color, will be used for transparent images
361 # in Internet Explorer/Windows instead of default black.
362 $cmd = $wgImageMagickConvertCommand .
363 " -quality 85 -background white -geometry {$width} ".
364 escapeshellarg($this->imagePath) . " " .
365 escapeshellarg($thumbPath);
366 $conv = shell_exec( $cmd );
367 } else {
368 # Use PHP's builtin GD library functions.
369 #
370 # First find out what kind of file this is, and select the correct
371 # input routine for this.
372
373 $truecolor = false;
374
375 switch( $this->type ) {
376 case 1: # GIF
377 $src_image = imagecreatefromgif( $this->imagePath );
378 break;
379 case 2: # JPG
380 $src_image = imagecreatefromjpeg( $this->imagePath );
381 $truecolor = true;
382 break;
383 case 3: # PNG
384 $src_image = imagecreatefrompng( $this->imagePath );
385 $truecolor = ( $this->bits > 8 );
386 break;
387 case 15: # WBMP for WML
388 $src_image = imagecreatefromwbmp( $this->imagePath );
389 break;
390 case 16: # XBM
391 $src_image = imagecreatefromxbm( $this->imagePath );
392 break;
393 default:
394 return 'Image type not supported';
395 break;
396 }
397 $height = floor( $this->height * ( $width/$this->width ) );
398 if ( $truecolor ) {
399 $dst_image = imagecreatetruecolor( $width, $height );
400 } else {
401 $dst_image = imagecreate( $width, $height );
402 }
403 imagecopyresampled( $dst_image, $src_image,
404 0,0,0,0,
405 $width, $height, $this->width, $this->height );
406 switch( $this->type ) {
407 case 1: # GIF
408 case 3: # PNG
409 case 15: # WBMP
410 case 16: # XBM
411 #$thumbUrl .= ".png";
412 #$thumbPath .= ".png";
413 imagepng( $dst_image, $thumbPath );
414 break;
415 case 2: # JPEG
416 #$thumbUrl .= ".jpg";
417 #$thumbPath .= ".jpg";
418 imageinterlace( $dst_image );
419 imagejpeg( $dst_image, $thumbPath, 95 );
420 break;
421 default:
422 break;
423 }
424 imagedestroy( $dst_image );
425 imagedestroy( $src_image );
426
427
428 }
429 #
430 # Check for zero-sized thumbnails. Those can be generated when
431 # no disk space is available or some other error occurs
432 #
433 $thumbstat = stat( $thumbPath );
434 if( $thumbstat['size'] == 0 )
435 {
436 unlink( $thumbPath );
437 }
438
439 # Purge squid
440 # This has to be done after the image is updated and present for all machines on NFS,
441 # or else the old version might be stored into the squid again
442 if ( $wgUseSquid ) {
443 $urlArr = Array(
444 $wgInternalServer.$thumbUrl
445 );
446 wfPurgeSquidServers($urlArr);
447 }
448 }
449 return $thumbUrl;
450 } // END OF function createThumb
451
452 /**
453 * Return the image history of this image, line by line.
454 * starts with current version, then old versions.
455 * uses $this->historyLine to check which line to return:
456 * 0 return line for current version
457 * 1 query for old versions, return first one
458 * 2, ... return next old version from above query
459 *
460 * @access public
461 */
462 function nextHistoryLine()
463 {
464 $fname = 'Image::nextHistoryLine()';
465 $dbr =& wfGetDB( DB_SLAVE );
466 if ( $this->historyLine == 0 ) {// called for the first time, return line from cur
467 $this->historyRes = $dbr->select( 'image',
468 array( 'img_size','img_description','img_user','img_user_text','img_timestamp', "'' AS oi_archive_name" ),
469 array( 'img_name' => $this->title->getDBkey() ),
470 $fname
471 );
472 if ( 0 == wfNumRows( $this->historyRes ) ) {
473 return FALSE;
474 }
475 } else if ( $this->historyLine == 1 ) {
476 $this->historyRes = $dbr->select( 'oldimage',
477 array( 'oi_size AS img_size', 'oi_description AS img_description', 'oi_user AS img_user',
478 'oi_user_text AS img_user_text', 'oi_timestamp AS img_timestamp', 'oi_archive_name'
479 ), array( 'oi_name' => $this->title->getDBkey() ), $fname, array( 'ORDER BY' => 'oi_timestamp DESC' )
480 );
481 }
482 $this->historyLine ++;
483
484 return $dbr->fetchObject( $this->historyRes );
485 }
486
487 /**
488 * Reset the history pointer to the first element of the history
489 * @access public
490 */
491 function resetHistory()
492 {
493 $this->historyLine = 0;
494 }
495
496 /**
497 * Return true if the file is of a type that can't be directly
498 * rendered by typical browsers and needs to be re-rasterized.
499 * @return bool
500 */
501 function mustRender() {
502 return ( $this->extension == 'svg' );
503 }
504
505 } //class
506
507
508 /**
509 * Returns the image directory of an image
510 * If the directory does not exist, it is created.
511 * The result is an absolute path.
512 *
513 * @param string $fname file name of the image file
514 * @access public
515 */
516 function wfImageDir( $fname )
517 {
518 global $wgUploadDirectory, $wgHashedUploadDirectory;
519
520 if (!$wgHashedUploadDirectory) { return $wgUploadDirectory; }
521
522 $hash = md5( $fname );
523 $oldumask = umask(0);
524 $dest = $wgUploadDirectory . '/' . $hash{0};
525 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
526 $dest .= '/' . substr( $hash, 0, 2 );
527 if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }
528
529 umask( $oldumask );
530 return $dest;
531 }
532
533 /**
534 * Returns the image directory of an image's thubnail
535 * If the directory does not exist, it is created.
536 * The result is an absolute path.
537 *
538 * @param string $fname file name of the thumbnail file, including file size prefix
539 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the thumbnail. Default is 'thumb'
540 * @access public
541 */
542 function wfImageThumbDir( $fname , $subdir='thumb')
543 {
544 return wfImageArchiveDir( $fname, $subdir );
545 }
546
547 /**
548 * Returns the image directory of an image's old version
549 * If the directory does not exist, it is created.
550 * The result is an absolute path.
551 *
552 * @param string $fname file name of the thumbnail file, including file size prefix
553 * @param string $subdir (optional) subdirectory of the image upload directory that should be used for storing the old version. Default is 'archive'
554 * @access public
555 */
556 function wfImageArchiveDir( $fname , $subdir='archive')
557 {
558 global $wgUploadDirectory, $wgHashedUploadDirectory;
559
560 if (!$wgHashedUploadDirectory) { return $wgUploadDirectory.'/'.$subdir; }
561
562 $hash = md5( $fname );
563 $oldumask = umask(0);
564
565 # Suppress warning messages here; if the file itself can't
566 # be written we'll worry about it then.
567 $archive = $wgUploadDirectory.'/'.$subdir;
568 if ( ! is_dir( $archive ) ) { @mkdir( $archive, 0777 ); }
569 $archive .= '/' . $hash{0};
570 if ( ! is_dir( $archive ) ) { @mkdir( $archive, 0777 ); }
571 $archive .= '/' . substr( $hash, 0, 2 );
572 if ( ! is_dir( $archive ) ) { @mkdir( $archive, 0777 ); }
573
574 umask( $oldumask );
575 return $archive;
576 }
577
578 /**
579 * Record an image upload in the upload log.
580 */
581 function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source = "" )
582 {
583 global $wgUser, $wgLang, $wgTitle, $wgOut, $wgDeferredUpdateList;
584 global $wgUseCopyrightUpload;
585
586 $fname = 'wfRecordUpload';
587 $dbw =& wfGetDB( DB_MASTER );
588
589 # img_name must be unique
590 if ( !$dbw->indexUnique( 'image', 'img_name' ) && !$dbw->indexExists('image','PRIMARY') ) {
591 wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
592 }
593
594
595 $now = wfTimestampNow();
596 $won = wfInvertTimestamp( $now );
597 $size = IntVal( $size );
598
599 if ( $wgUseCopyrightUpload )
600 {
601 $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
602 '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
603 '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
604 }
605 else $textdesc = $desc ;
606
607 $now = wfTimestampNow();
608 $won = wfInvertTimestamp( $now );
609
610 # Test to see if the row exists using INSERT IGNORE
611 # This avoids race conditions by locking the row until the commit, and also
612 # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
613 $dbw->insertArray( 'image',
614 array(
615 'img_name' => $name,
616 'img_size'=> $size,
617 'img_timestamp' => $dbw->timestamp($now),
618 'img_description' => $desc,
619 'img_user' => $wgUser->getID(),
620 'img_user_text' => $wgUser->getName(),
621 ), $fname, 'IGNORE'
622 );
623 $descTitle = Title::makeTitleSafe( NS_IMAGE, $name );
624
625 if ( $dbw->affectedRows() ) {
626 # Successfully inserted, this is a new image
627 $id = $descTitle->getArticleID();
628
629 if ( $id == 0 ) {
630 $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
631 $dbw->insertArray( 'cur',
632 array(
633 'cur_id' => $seqVal,
634 'cur_namespace' => NS_IMAGE,
635 'cur_title' => $name,
636 'cur_comment' => $desc,
637 'cur_user' => $wgUser->getID(),
638 'cur_user_text' => $wgUser->getName(),
639 'cur_timestamp' => $dbw->timestamp($now),
640 'cur_is_new' => 1,
641 'cur_text' => $textdesc,
642 'inverse_timestamp' => $won,
643 'cur_touched' => $dbw->timestamp($now)
644 ), $fname
645 );
646 $id = $dbw->insertId() or 0; # We should throw an error instead
647
648 RecentChange::notifyNew( $now, $descTitle, 0, $wgUser, $desc );
649
650 $u = new SearchUpdate( $id, $name, $desc );
651 $u->doUpdate();
652 }
653 } else {
654 # Collision, this is an update of an image
655 # Get current image row for update
656 $s = $dbw->getArray( 'image', array( 'img_name','img_size','img_timestamp','img_description',
657 'img_user','img_user_text' ), array( 'img_name' => $name ), $fname, 'FOR UPDATE' );
658
659 # Insert it into oldimage
660 $dbw->insertArray( 'oldimage',
661 array(
662 'oi_name' => $s->img_name,
663 'oi_archive_name' => $oldver,
664 'oi_size' => $s->img_size,
665 'oi_timestamp' => $dbw->timestamp($s->img_timestamp),
666 'oi_description' => $s->img_description,
667 'oi_user' => $s->img_user,
668 'oi_user_text' => $s->img_user_text
669 ), $fname
670 );
671
672 # Update the current image row
673 $dbw->updateArray( 'image',
674 array( /* SET */
675 'img_size' => $size,
676 'img_timestamp' => $dbw->timestamp(),
677 'img_user' => $wgUser->getID(),
678 'img_user_text' => $wgUser->getName(),
679 'img_description' => $desc,
680 ), array( /* WHERE */
681 'img_name' => $name
682 ), $fname
683 );
684
685 # Invalidate the cache for the description page
686 $descTitle->invalidateCache();
687 }
688
689 $log = new LogPage( 'upload' );
690 $log->addEntry( 'upload', $descTitle, $desc );
691 }
692
693 /**
694 * Returns the image URL of an image's old version
695 *
696 * @param string $fname file name of the image file
697 * @param string $subdir (optional) subdirectory of the image upload directory that is used by the old version. Default is 'archive'
698 * @access public
699 */
700 function wfImageArchiveUrl( $name, $subdir='archive' )
701 {
702 global $wgUploadPath, $wgHashedUploadDirectory;
703
704 if ($wgHashedUploadDirectory) {
705 $hash = md5( substr( $name, 15) );
706 $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' .
707 substr( $hash, 0, 2 ) . '/'.$name;
708 } else {
709 $url = $wgUploadPath.'/'.$subdir.'/'.$name;
710 }
711 return wfUrlencode($url);
712 }
713
714 /**
715 * Return a rounded pixel equivalent for a labeled CSS/SVG length.
716 * http://www.w3.org/TR/SVG11/coords.html#UnitIdentifiers
717 *
718 * @param string $length
719 * @return int Length in pixels
720 */
721 function scaleSVGUnit( $length ) {
722 static $unitLength = array(
723 'px' => 1.0,
724 'pt' => 1.25,
725 'pc' => 15.0,
726 'mm' => 3.543307,
727 'cm' => 35.43307,
728 'in' => 90.0,
729 '' => 1.0, // "User units" pixels by default
730 '%' => 2.0, // Fake it!
731 );
732 if( preg_match( '/^(\d+)(em|ex|px|pt|pc|cm|mm|in|%|)$/', $length, $matches ) ) {
733 $length = FloatVal( $matches[1] );
734 $unit = $matches[2];
735 return round( $length * $unitLength[$unit] );
736 } else {
737 // Assume pixels
738 return round( FloatVal( $length ) );
739 }
740 }
741
742 /**
743 * Compatible with PHP getimagesize()
744 * @todo support gzipped SVGZ
745 * @todo check XML more carefully
746 * @todo sensible defaults
747 *
748 * @param string $filename
749 * @return array
750 */
751 function getSVGsize( $filename ) {
752 $width = 256;
753 $height = 256;
754
755 // Read a chunk of the file
756 $f = fopen( $filename, "rt" );
757 if( !$f ) return false;
758 $chunk = fread( $f, 4096 );
759 fclose( $f );
760
761 // Uber-crappy hack! Run through a real XML parser.
762 if( !preg_match( '/<svg\s*([^>]*)\s*>/s', $chunk, $matches ) ) {
763 return false;
764 }
765 $tag = $matches[1];
766 if( preg_match( '/\bwidth\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
767 $width = scaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
768 }
769 if( preg_match( '/\bheight\s*=\s*("[^"]+"|\'[^\']+\')/s', $tag, $matches ) ) {
770 $height = scaleSVGUnit( trim( substr( $matches[1], 1, -1 ) ) );
771 }
772
773 return array( $width, $height, 'SVG',
774 "width=\"$width\" height=\"$height\"" );
775 }
776
777 ?>