コード例 #1
0
 function sgThumbnail(&$img, $type)
 {
     $this->config = sgConfig::getInstance();
     $this->image = $img;
     $widthVar = "thumb_width_" . $type;
     $heightVar = "thumb_height_" . $type;
     $cropVar = "thumb_crop_" . $type;
     $this->maxWidth = $this->config->{$widthVar};
     $this->maxHeight = $this->config->{$heightVar};
     if (isset($this->config->{$cropVar})) {
         $this->forceSize = $this->config->{$cropVar};
     }
     if ($this->image == null) {
         return;
     }
     $this->imagePath = $this->image->realPath();
     $this->thumbPath = $this->config->base_path . Singapore::thumbnailPath($this->image->parent->id, $this->image->id, $this->maxWidth, $this->maxHeight, $this->forceSize);
     $this->thumbURL = $this->config->base_url . Singapore::thumbnailPath($this->image->parent->id, $this->image->id, $this->maxWidth, $this->maxHeight, $this->forceSize);
     //security check: make sure requested file is in galleries directory
     if (!Singapore::isSubPath($this->config->base_path . $this->config->pathto_galleries, $this->imagePath) && !$this->image->isRemote()) {
         return;
     }
     //security check: make sure $image has a valid extension
     if (!$this->image->isRemote() && !preg_match("/.+\\.(" . $this->config->recognised_extensions . ")\$/i", $this->image->id)) {
         return;
     }
     $this->calculateDimensions();
     //link straight to image if it smaller than required size
     if ($this->image->width <= $this->thumbWidth && $this->image->height <= $this->thumbHeight) {
         $this->thumbURL = $this->image->realURL();
         return;
     }
     $imageModified = @filemtime($this->imagePath);
     $thumbModified = @filemtime($this->thumbPath);
     if ($imageModified > $thumbModified || !$thumbModified) {
         $this->buildThumbnail();
     }
 }