[Mediawiki-l] Is there a way to limit the size of images uploaded

Brion Vibber brion at wikimedia.org
Wed Jan 9 19:31:47 UTC 2008


Norbert Hoeller wrote:
> The problem is more likely to occur in a shared web server environment 
> where you are limited in how much memory can be allocated to PHP.  In my 
> case, my service provider claims that 20M is the maximum, although 
> phpinfo() reports 40M.  As other posts have pointed out, it is the number 
> of pixels that determine how large the uncompressed image is.  An other 
> factor would be the color depth: 8-, 16- or 24-bit.  Displaying the images 
> natively is not a problem, since the images do not need to be 
> uncompressed.  I have seen indications that ImageMagick requires less 
> memory than the standard GD library when creating thumbnails, but have not 
> been able to test myself (standard ImageMagick install will not work in a 
> shared environment).

There are three main benefits of using ImageMagick:

1) Better scaling quality

2) Since it runs out of process, if the scaling fails (eg due to memory
limits), the rest of the wiki keeps running. You just don't have a
working image.

3) For JPEG images (at least in some versions), ImageMagick can scale
large images without decompressing the entire file into memory/scratch
space first. (GIF and PNG images still require loading the whole thing.)

How much memory (or scratch disk) ImageMagick will actually use depends
on what mode it's been compiled in (8-bit, 16-bit, or 32-bit pixel
depth), but you don't always have to worry too much about that.


MediaWiki has a switch to disable scaling of very large images:

/**
 * Don't thumbnail an image if it will use too much working memory
 * Default is 50 MB if decompressed to RGBA form, which corresponds to
 * 12.5 million pixels or 3500x3500
 */
$wgMaxImageArea = 1.25e7;

You can decrease that size to keep large images from breaking the entire
system... *however* it isn't applied to JPEG images due to ImageMagick's
nicer behavior with them.

To make it apply to JPEGs as well (eg for GD) you might have to hack out
the exception for now. Probably we should fix it to check this
automatically.

(In current MediaWiki this is in includes/media/Bitmap.php. In older
versions you'll probably find it in includes/Image.php)

-- brion vibber (brion @ wikimedia.org)



More information about the MediaWiki-l mailing list