/** * Load metadata from the file itself */ function loadFromFile() { global $wgUseSharedUploads, $wgSharedUploadDirectory, $wgLang, $wgShowEXIF; $fname = 'Image::loadFromFile'; wfProfileIn($fname); $this->imagePath = $this->getFullPath(); $this->fileExists = file_exists($this->imagePath); $this->fromSharedDirectory = false; $gis = array(); if (!$this->fileExists) { wfDebug("{$fname}: " . $this->imagePath . " not found locally!\n"); } # If the file is not found, and a shared upload directory is used, look for it there. if (!$this->fileExists && $wgUseSharedUploads && $wgSharedUploadDirectory) { # In case we're on a wgCapitalLinks=false wiki, we # capitalize the first letter of the filename before # looking it up in the shared repository. $sharedImage = Image::newFromName($wgLang->ucfirst($this->name)); $this->fileExists = file_exists($sharedImage->getFullPath(true)); if ($this->fileExists) { $this->name = $sharedImage->name; $this->imagePath = $this->getFullPath(true); $this->fromSharedDirectory = true; } } if ($this->fileExists) { $magic =& wfGetMimeMagic(); $this->mime = $magic->guessMimeType($this->imagePath, true); $this->type = $magic->getMediaType($this->imagePath, $this->mime); # Get size in bytes $this->size = filesize($this->imagePath); $magic =& wfGetMimeMagic(); # Height and width if ($this->mime == 'image/svg') { wfSuppressWarnings(); $gis = wfGetSVGsize($this->imagePath); wfRestoreWarnings(); } elseif (!$magic->isPHPImageType($this->mime)) { # Don't try to get the width and height of sound and video files, that's bad for performance $gis[0] = 0; //width $gis[1] = 0; //height $gis[2] = 0; //unknown $gis[3] = ""; //width height string } else { wfSuppressWarnings(); $gis = getimagesize($this->imagePath); wfRestoreWarnings(); } wfDebug("{$fname}: " . $this->imagePath . " loaded, " . $this->size . " bytes, " . $this->mime . ".\n"); } else { $gis[0] = 0; //width $gis[1] = 0; //height $gis[2] = 0; //unknown $gis[3] = ""; //width height string $this->mime = NULL; $this->type = MEDIATYPE_UNKNOWN; wfDebug("{$fname}: " . $this->imagePath . " NOT FOUND!\n"); } $this->width = $gis[0]; $this->height = $gis[1]; #NOTE: $gis[2] contains a code for the image type. This is no longer used. #NOTE: we have to set this flag early to avoid load() to be called # be some of the functions below. This may lead to recursion or other bad things! # as ther's only one thread of execution, this should be safe anyway. $this->dataLoaded = true; if ($this->fileExists && $wgShowEXIF) { $this->metadata = serialize($this->retrieveExifData()); } else { $this->metadata = serialize(array()); } if (isset($gis['bits'])) { $this->bits = $gis['bits']; } else { $this->bits = 0; } wfProfileOut($fname); }
function getImageSize($image, $path) { return wfGetSVGsize($path); }