Exemplo n.º 1
0
}elseif(file_exists($TemplateImageFile)) {
	if(!is_dir(ISC_BASE_PATH . '/cache/tplthumbs/')) {
		isc_mkdir(ISC_BASE_PATH . '/cache/tplthumbs/');
	}
	if((strtolower(substr($TemplateImageFile,-4)) == ".jpg" || strtolower(substr($TemplateImageFile,-5)) == ".jpeg") && function_exists('imagejpeg')) {
		// jpeg image
		header("Content-type: image/jpeg");
		$writeOptions = new ISC_IMAGE_WRITEOPTIONS_JPEG();
	}elseif(strtolower(substr($TemplateImageFile,-4)) == ".gif" && function_exists('imagegif') ) {
		// gif image
		header("Content-type: image/gif");
		$writeOptions = new ISC_IMAGE_WRITEOPTIONS_GIF();
	}
	header("Last-Modified: " . gmdate("r"));

	$image = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($TemplateImageFile);
	$image->loadImageFileToScratch();
	$image->resampleScratchToMaximumDimensions(200, 200);
	$image->saveScratchToFile($CacheTemplateImageFile, $writeOptions);
	unset($image);

	if(file_exists($CacheTemplateImageFile)) {
		echo file_get_contents($CacheTemplateImageFile);
	}
	else {
		OutputNoImage();
	}
	die();

}else {
	OutputNoImage();
Exemplo n.º 2
0
	/**
	 * Save an incoming vendor image (from the user's browser) in to the file system.
	 *
	 * @param int The vendor ID that this image should be attached to.
	 * @param string The type of image to upload - either self::VENDOR_LOGO or self::VENDOR_PHOTO
	 * @return string The path to the vendor image uploaded.
	 */
	private function SaveVendorImage($vendorId, $imageType)
	{
		// No image to save, so it's OK
		if(!isset($_FILES['vendor'.$imageType]) || !is_uploaded_file($_FILES['vendor'.$imageType]['tmp_name'])) {
			return '';
		}

		$maxDimensions = GetConfig('Vendor'.ucfirst($imageType).'Size');
		if(!$maxDimensions) {
			@unlink($_FILES['vendor'.$imageType]['tmp_name']);
			return '';
		}
		list($maxWidth, $maxHeight) = explode('x', $maxDimensions);

		$ext = GetFileExtension($_FILES['vendor'.$imageType]['name']);
		$imageName = 'vendor_images/'.$vendorId.'_'.$imageType.'.'.$ext;
		$destLocation = ISC_BASE_PATH.'/'.GetConfig('ImageDirectory').'/'.$imageName;

		// Attempt to move the image over (some hosts have problems working with files in the temp directory)
		if(!move_uploaded_file($_FILES['vendor'.$imageType]['tmp_name'], $destLocation)) {
			@unlink($_FILES['vendor'.$imageType]['tmp_name']);
			return false;
		}

		try {
			$image = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($destLocation);
			$image->loadImageFileToScratch();
			$image->resampleScratchToMaximumDimensions($maxWidth, $maxHeight);

			// simulate behaviour of old GenerateThumbnail function which would save to the same format as the original
			switch ($image->getImageType()) {
				case IMAGETYPE_GIF:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_GIF;
					break;

				case IMAGETYPE_JPEG:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_JPEG;
					break;

				case IMAGETYPE_PNG:
					$writeOptions = new ISC_IMAGE_WRITEOPTIONS_PNG;
					break;
			}

			$image->saveScratchToFile($destLocation, $writeOptions);
		} catch (Exception $exception) {
			return false;
		}

		// Otherwise, return the location of the image
		return $imageName;
	}
Exemplo n.º 3
0
	/**
	* Returns the width and height of the actual resized version of a product image in the form of an arrray where index 0 is width, index 1 is height.
	*
	* @param int $size One of the defined ISC_PRODUCT_IMAGE_SIZE_? constants
	* @param bool $generate If necessary, generate the resized image to determine it's size otherwise will rely purely on any internally cached values. If this is called with $generate as false and no value has been stored yet, null will be returned.
	* @param bool $save If necessary, update image in the database with the correct sizes
	* @throws ISC_PRODUCT_IMAGE_INVALIDSIZE_EXCEPTION If an invalid size is specified
	* @return array index 0 is width, index 1 is height
	*/
	public function getResizedFileDimensions($size, $generate = true, $save = true)
	{
		if ($generate || $this->_resizedFileDimensions[$size] === null) {
			$imageFilePath = $this->getAbsoluteResizedFilePath($size, $generate, $save);

			// if the call above actually generated the file then the size will now be cached and we don't need to calculate it again
			if ($this->_resizedFileDimensions[$size] === null) {
				try {
					$library = ISC_IMAGE_LIBRARY_FACTORY::getImageLibraryInstance($imageFilePath);
					$this->_resizedFileDimensions[$size] = array($library->getWidth(), $library->getHeight());
				} catch (ISC_IMAGE_LIBRARY_FACTORY_FILEDOESNTEXIST_EXCEPTION $exception) {
					// do nothing, keep size as null
				}
			}
		}

		return $this->_resizedFileDimensions[$size];
	}