function setSize($width, $height, $sizeDefault = 'imagesize') { global $wgUser; #print "[WHq: $width, $height]"; if ($height) { $height = (int) $height; } if ($width) { $width = (int) $width; } if ($height <= 0) { $height = null; } if ($width <= 0) { $width = null; } if ($this->mediatype == MEDIATYPE_AUDIO) { //HACK! this actually depends on the player used, and thus on the mime type. $imgwidth = 250; $imgheight = 140; if (!$width) { $width = $imgwidth; } if (!$height) { $height = $height; } } else { $imgwidth = $this->image->getWidth(); $imgheight = $this->image->getHeight(); if ($this->mediatype == MEDIATYPE_VIDEO && (!$imgwidth || !$imgheight)) { $dim = Player::detectVideoResolution($this->image, $this->mimetype); if ($dim) { list($imgwidth, $imgheight) = $dim; //TODO: store in DataBase! } } } $imgratio = $imgheight && $imgwidth ? (double) $imgwidth / (double) $imgheight : 1; #print "[WH0: $width, $height; $imgwidth, $imgheight ~$imgratio]"; if (!$width && !$height) { $wopt = @$this->options['playersize']; if ($wopt) { if (preg_match('/([it])?(\\d+)/i', $wopt, $m)) { $sz = @$m[1]; if ($sz && strtolower($sz) == 't') { $sizeDefault = 'thumbsize'; } else { $sizeDefault = 'imagesize'; } $wopt = (int) $m[2]; } else { $wopt = false; } } if (!$wopt) { $wopt = $wgUser->getGlobalPreference($sizeDefault); } if ($sizeDefault == 'thumbsize') { $limits = $GLOBALS['wgThumbLimits']; } else { $limits = $GLOBALS['wgImageLimits']; } if (!isset($limits[$wopt])) { $wopt = User::getDefaultGlobalPreference($sizeDefault); } list($width, $height) = $limits[$wopt]; if (!$width) { $width = $sizeDefault == 'thumbsize' ? 180 : 600; } } #print "[WH1: $width, $height]"; if ($imgwidth && $width > $imgwidth) { if ($height) { $height = ceil($height * ((double) $imgwidth / $width)); } $width = $imgwidth; } if ($imgheight && $height > $imgheight) { if ($width) { $width = ceil($width * ((double) $imgheight / $height)); } $height = $imgheight; } #print "[WH2: $width, $height]"; if (!$width) { $width = ceil($height * $imgratio); } elseif (!$height) { $height = ceil($width / $imgratio); } #print "[WH3: $width, $height]"; $this->width = $width; $this->height = $height; }