HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/lib/imageman/imageman.php
<?php

class ImageMan
{
	private
		/**
		 * @name _file
		 * @desc The file name currently being used. Null if a new image is being created.
		 */
		$_file = null,
		
		/**
		 * @name _type
		 * @desc The image type of the image that was opened.
		 */
		$_type = null,
		
		/**
		 * @name _imageInstance
		 * @desc The instance of the image resource currently being manipulated.
		 */
		$_imageInstance = null,
		
		$_width,
		$_height;
	
	
	
	/**
	 * @name   __construct
	 * @desc   The constructor
	 * @return Object
	 */
	public function __construct($file = null)
	{
		$info = null;
		
		if (is_string($file)) {
			$file = realpath($file);
			$info = getimagesize($file);
			
			if ($info) {
				// filename
				$this->_file = $file;
				
				// image instance
				$this->_imageInstance = imagecreatefromstring(file_get_contents($file));
			}
		} elseif (@imagesx($file) !== false) {
			$this->_imageInstance = $file;
			
			$info = array(
					imagesx($file),
					imagesy($file),
					IMAGETYPE_JPEG
				);
		}
		
		if ($info) {
			// set dimensions
			$this->_width  = $info[0];
			$this->_height = $info[1];
			
			// set type
			$this->_type = $info[2];
		}
		
		if ($this->_imageInstance) {
			// for images with alpha transparency
			imagesavealpha($this->_imageInstance, true);
			imagealphablending($this->_imageInstance, true);
		}
	}
	
	/**
	 * @name   __toString
	 * @desc   Outputs the image to the browser.
	 * @return String
	 */
	public function __toString()
	{
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
		header('Cache-Control: no-store, no-cache, must-revalidate');
		header('Cache-Control: post-check=0, pre-check=0', false);
		header('Pragma: no-cache');
		header('Content-Type: ' . image_type_to_mime_type($this->_type));
		
		return $this->getImageString();
	}
	
	
	
	/**
	 * @name   save
	 * @desc   Saves an image. Returns false if it failed, returns the ImageMan object if successful.
	 * @return Mixed
	 */
	public function save($file = false, $overwrite = true)
	{
		// if no filename was supplied assume the current one
		if (!$file && $this->_file) {
			$file = $this->_file;
		}
		
		if (!$file) {
			return false;
		}
		
		// of overwriting of the file doesn't exist
		if ($overwrite || !is_file($file)) {
			// save it
			file_put_contents($file, $this->getImageString());
			
			// return the object isntance
			return $this;
		}
		
		// failed
		return false;
	}
	
	public function close()
	{
		return imagedestroy($this->_imageInstance);
	}
	
	public function getImage()
	{
		return $this->_imageInstance;
	}
	
	/**
	 * @name   getImageString
	 * @desc   Returns a binary string of the image as if it were the image file contents.
	 * @return String
	 */
	public function getImageString()
	{
		// default output is jpg
		switch ($this->_type) {
			case IMAGETYPE_PNG:
				$func = 'png';
			break;
			
			case IMAGETYPE_GIF:
				$func = 'gif';
			break;
			
			default:
				$func = 'jpeg';
		}
		
		// set the output function
		$func = 'image' . $func;
		
		ob_start();
		
		$func($this->_imageInstance);
		
		return ob_get_clean();
	}
	
	/**
	 * @name   resize
	 * @desc   Resizes the image constraining the proportions if so desired.
	 */
	public function resize($width = null, $height = null)
	{
		$temp = imagecreatetruecolor($width, $height);
		
		// re-copy the image
		imagecopyresampled($temp, $this->_imageInstance, 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
		
		$this->__construct($temp);
		
		return $this;
	}
	
	/**
	 * @name   crop
	 * @desc   Crops an image starting at the specified coordinates. The dimensions are used to calculate the end cropping
	 *         point of the image.
	 * @return Object self
	 * @param  Number $x
	 * @param  Number $y
	 */
	public function crop($x = 0, $y = 0, $width = 0, $height = 0)
	{
		if (!$width || $width > $this->_width - $x) {
			$width = $this->_width - $x;
		}
		
		if (!$height || $height > $this->_height - $y) {
			$height = $this->_height - $x;
		}
		
		$temp = imagecreatetruecolor($width, $height);
		
		// re-copy the image
		imagecopyresampled($temp, $this->_imageInstance, 0, 0, $x, $y, $width, $height, $width, $height);
		
		$this->__construct($temp);
		
		return $this;
	}
}