Example #1
0
	/**
	 * Get the preview file with the contents copied over resized/previewed.
	 *
	 * @param string $dimensions
	 *
	 * @return Filestore\File
	 */
	public function getPreviewFile($dimensions = '300x300') {
		if($this->_ftp->isLocal){
			return $this->_getTmpLocal()->getPreviewFile($dimensions);
		}
		else{
			$bits         = \Core\Filestore\get_resized_key_components($dimensions, $this);
			$resized      = Filestore\Factory::File($bits['dir'] . $bits['key']);

			if(!$resized->exists()){
				// The file doesn't exist yet, so download the original, resize it, and upload the resulting image.

				// Download.
				$local = $this->_getTmpLocal();
				// Resize
				$localresized = $local->getPreviewFile($dimensions);
				// And upload.
				$localresized->copyTo($resized);
			}

			return $resized;
		}
	}
Example #2
0
	public function getPreviewFile($dimensions = '300x300'){
		// If the system is getting too close to the max_execution_time variable, just return the mimetype!
		// One note though, this is only available when running php from the web.
		// CLI scripts don't have it!
		if(ini_get('max_execution_time') && \Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->getTime() + 5 >= ini_get('max_execution_time')){
			// Try and get the mime icon for this file.
			$filemime = str_replace('/', '-', $this->getMimetype());

			$file = Factory::File('assets/images/mimetypes/' . $filemime . '.png');
			if(!$file->exists()){
				$file = Factory::File('assets/images/mimetypes/unknown.png');
			}
			return $file;
		}

		// This will get me the file, but none of the data or anything.
		$file = $this->getQuickPreviewFile($dimensions);

		$bits   = \Core\Filestore\get_resized_key_components($dimensions, $this);
		$width  = $bits['width'];
		$height = $bits['height'];
		$mode   = $bits['mode'];
		$key    = $bits['key'];

		// dunno how this may work... but prevent the possible infinite loop scenario.
		if($file == $this){
			return $this;
		}

		if (!$this->exists()) {
			// This will be a 404 image.
			//$file = \Core\Filestore\Factory::File('assets/images/mimetypes/notfound.png');
			return $file->getPreviewFile($dimensions);
		}
		elseif ($this->isPreviewable()) {
			// If no resize was requested, simply return the full size image.
			if($width === false) return $file;

			// if this file was smaller than the requested size, (and the mode isn't set to force the size)...
			$currentdata = getimagesize($this->getFilename());
			if(($mode == '' || $mode == '<') && $currentdata[0] <= $width){
				return $this;
			}
			//var_dump($currentdata, $width, $mode); die();

			if (!$file->exists()) {
				$this->_resizeTo($file, $width, $height, $mode);
			}

			return $file;
		}
		else {
			// This will be a mimetype image.
			return $file->getPreviewFile($dimensions);
		}
	}