Rasterize plain image views of SVG files at default size (currently 512px wide, maybe...
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Oct 2004 07:35:19 +0000 (07:35 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Oct 2004 07:35:19 +0000 (07:35 +0000)
Prefer ImageMagick over GD when setting up LocalSettings.php

config/index.php
includes/Image.php
includes/ImagePage.php
includes/Skin.php

index be5cffe..4aaaa9f 100644 (file)
@@ -279,20 +279,24 @@ if( $conf->zlib ) {
 }
 
 $conf->ImageMagick = false;
+$imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
+foreach( $imcheck as $dir ) {
+       $im = "$dir/convert";
+       if( file_exists( $im ) ) {
+               print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
+               $conf->ImageMagick = $im;
+               break;
+       }
+}
 
 $conf->HaveGD = function_exists( "imagejpeg" );
 if( $conf->HaveGD ) {
-       print "<li>Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads.</li>\n";
-} else {
-       $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin" );
-       foreach( $imcheck as $dir ) {
-               $im = "$dir/convert";
-               if( file_exists( $im ) ) {
-                       print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
-                       $conf->ImageMagick = $im;
-                       break;
-               }
+       print "<li>Found GD graphics library built-in";
+       if( !$conf->ImageMagick ) {
+               print ", image thumbnailing will be enabled if you enable uploads";
        }
+       print ".</li>\n";
+} else {
        if( !$conf->ImageMagick ) {
                print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
        }
index 24c7896..3cb0a09 100644 (file)
@@ -121,6 +121,14 @@ class Image
        {
                return $this->url;
        }
+       
+       function getViewURL() {
+               if( $this->mustRender() ) {
+                       return $this->createThumb( $this->getWidth() );
+               } else {
+                       return $this->getURL();
+               }
+       }
 
        /**
         * Return the image path of the image in the
@@ -319,7 +327,7 @@ class Image
 
                if( $width > $this->width ) {
                        # Don't make an image bigger than the source
-                       return $this->getURL();
+                       return $this->getViewURL();
                }
 
                if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) {
@@ -461,7 +469,15 @@ class Image
                $this->historyLine = 0;
        }
 
-
+       /**
+        * Return true if the file is of a type that can't be directly
+        * rendered by typical browsers and needs to be re-rasterized.
+        * @return bool
+        */
+       function mustRender() {
+               return ( $this->extension == 'svg' );
+       }
+       
 } //class
 
 
index 1668197..f8b4c51 100644 (file)
@@ -39,7 +39,7 @@ class ImagePage extends Article {
        {
                global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
                $this->img  = Image::newFromTitle( $this->mTitle );
-               $url  = $this->img->getUrl();
+               $url  = $this->img->getViewURL();
                $anchoropen = '';
                $anchorclose = '';
                if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
index 652149a..a30d198 100644 (file)
@@ -1668,7 +1668,7 @@ class Skin {
        function makeImageLinkObj( $nt, $alt = '' ) {
                global $wgContLang, $wgUseImageResize;
                $img   = Image::newFromTitle( $nt );
-               $url   = $img->getURL();
+               $url   = $img->getViewURL();
 
                $align = '';
                $prefix = $postfix = '';
@@ -1799,7 +1799,7 @@ class Skin {
        function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
                global $wgStylePath, $wgContLang;
                # $image = Title::makeTitleSafe( NS_IMAGE, $name );
-               $url  = $img->getURL();
+               $url  = $img->getViewURL();
 
                #$label = htmlspecialchars( $label );
                $alt = preg_replace( '/<[^>]*>/', '', $label);
@@ -1843,7 +1843,7 @@ class Skin {
                {
                        $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
                        $manual_img = Image::newFromTitle( $manual_title );
-                       $thumbUrl = $manual_img->getURL();
+                       $thumbUrl = $manual_img->getViewURL();
                        if ( $manual_img->exists() )
                        {
                                $width  = $manual_img->getWidth();