/**
	* Returns an image manipulation library that is capable of handling the image file at $filePath -- will detect the image type and return the appropriate library from those available on the server
	*
	* @param string $filePath
	* @param bool $setInstanceFilePath
	* @return ISC_IMAGE_LIBRARY_INTERFACE
	* @throws ISC_IMAGE_LIBRARY_FACTORY_INVALIDIMAGEFILE_EXCEPTION If the image file at $filePath is not a valid image
	* @throws ISC_IMAGE_LIBRARY_FACTORY_NOPHPSUPPORT_EXCEPTION If there were no image libraries installed that could support the image
	*/
	public static function getImageLibraryInstance($filePath = null)
	{
		if ($filePath) {
			if (!file_exists($filePath)) {
				throw new ISC_IMAGE_LIBRARY_FACTORY_FILEDOESNTEXIST_EXCEPTION($filePath);
			}

			if (!self::isValidImageFile($filePath)) {
				throw new ISC_IMAGE_LIBRARY_FACTORY_INVALIDIMAGEFILE_EXCEPTION($filePath);
			}
		}

		// was going to use an array of classnames and call_user_func but it's a bit slow, and how often are libraries added? rarely
		// use direct calls instead

		try {
			if (ISC_IMAGE_LIBRARY_IMAGICK::isLibrarySupported() && (!$filePath || ISC_IMAGE_LIBRARY_IMAGICK::isFileSupported($filePath))) {
				$instance = new ISC_IMAGE_LIBRARY_IMAGICK($filePath);
			} else if (ISC_IMAGE_LIBRARY_GD::isLibrarySupported() && (!$filePath || ISC_IMAGE_LIBRARY_GD::isFileSupported($filePath))) {
				$instance = new ISC_IMAGE_LIBRARY_GD($filePath);
			} else {
				throw new ISC_IMAGE_LIBRARY_FACTORY_NOPHPSUPPORT_EXCEPTION($filePath);
			}
		} catch (ISC_IMAGE_BASECLASS_INVALIDIMAGE_EXCEPTION $exception) {
			throw new ISC_IMAGE_LIBRARY_FACTORY_INVALIDIMAGEFILE_EXCEPTION($filePath);
		}

		return $instance;
	}
예제 #2
0
	/**
	* Overlay another GD resource onto the current scratch at the given offset
	*
	* @param ISC_IMAGE_LIBRARY_GD $image
	* @param mixed $offsetX
	* @param mixed $offsetY
	*/
	public function overlayImage(ISC_IMAGE_LIBRARY_GD $image, $offsetX, $offsetY)
	{
		// when watermarking is implemented this may need to be re-examined for when gifs or 8bit pngs are used

		$overlayResource = $image->getScratchResource();
		$overlayWidth = $image->getWidth();
		$overlayHeight = $image->getHeight();

		if ($offsetX < 0) {
			$offsetX = $this->getWidth() + $offsetX - $overlayWidth;
		}

		if ($offsetY < 0) {
			$offsetY = $this->getHeight() + $offsetY - $overlayHeight;
		}

		imagecopyresampled($this->getScratchResource(), $overlayResource, $offsetX, $offsetY, 0, 0, $overlayWidth, $overlayHeight, $overlayWidth, $overlayHeight);
	}