ACC SHELL

Path : /srv/www/vhosts/alfa-com/engine/
File Upload :
Current File : /srv/www/vhosts/alfa-com/engine/Image.php

<?php
	// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
	
	class Image
	{
		public static function createFromFile($file)
		{
			$i = @imagecreatefromjpeg($file); if ($i) return $i;
			$i = @imagecreatefrompng($file); if ($i) return $i;
			$i = @imagecreatefromgif($file); if ($i) return $i;
			$i = @imagecreatefromwbmp($file); if ($i) return $i;
			return false;
		}
		
		public static function scale($i, $max_width, $max_height)
		{
			if ((imagesx($i) < $max_width) && (imagesy($i) < $max_height))
			{
				$j = @imagecreatetruecolor(imagesx($i), imagesy($i));
				imagecopy($j, $i, 0, 0, 0, 0, imagesx($i), imagesy($i));
				return $j;
			}
			if (imagesx($i) * $max_height < imagesy($i) * $max_width)
			{
				$width = round(imagesx($i) * $max_height / imagesy($i));
				$j = @imagecreatetruecolor($width, $max_height);
			}
			else
			{
				$height = round(imagesy($i) * $max_width / imagesx($i));
				$j = @imagecreatetruecolor($max_width, $height);
			}
			imagecopyresampled($j, $i, 0, 0, 0, 0, imagesx($j), imagesy($j), imagesx($i),  imagesy($i));
			return $j;
		}

		public static function scaleexpand($i, $max_width, $max_height, $color = 'ffffff', $transparent = false)
		{
			$temp = self::scale($i, $max_width, $max_height);
			$j = @imagecreatetruecolor($max_width, $max_height);
	
			$r = hexdec(substr($color, 0, 2));
			$g = hexdec(substr($color, 2, 2));
			$b = hexdec(substr($color, 4, 2));
			if ($transparent)
			{
				$color = imagecolorallocatealpha($j, $r, $g, $b, 127);
				imagecolortransparent($j, $color);
			}
			else
				$color = imagecolorallocate($j, $r, $g, $b);
			imagefilledrectangle($j, 0, 0, imagesx($j), imagesy($j), $color);
	
			imagecopy($j, $temp, (imagesx($j) - imagesx($temp)) / 2, (imagesy($j) - imagesy($temp)) / 2, 0, 0, imagesx($temp), imagesy($temp));
			imagedestroy($temp);
			return $j;
		}
	
		public static function scalecrop($i, $max_width, $max_height)
		{
			$j = @imagecreatetruecolor($max_width, $max_height);
			if (!$j)
				return false;
			if ((imagesx($i) < $max_width) && (imagesy($i) < $max_height))
			{
				imagecopy($j, $i, round(($max_width - imagesx($i)) / 2), round(($max_height - imagesy($i)) / 2), 0, 0, imagesx($i), imagesy($i));
				return $j;
			}
			if (imagesx($i) * $max_height < imagesy($i) * $max_width)
			{
				$height = round($max_height * imagesx($i) / $max_width);
				imagecopyresampled($j, $i, 0, 0, 0, round((imagesy($i) - $height) / 2), imagesx($j), imagesy($j), imagesx($i), $height);
			}
			else
			{
				$width = round($max_width * imagesy($i) / $max_height);
				imagecopyresampled($j, $i, 0, 0, round((imagesx($i) - $width) / 2), 0, imagesx($j), imagesy($j), $width, imagesy($i));
			}
			return $j;
		}
	
		public static function thumb($blob, $function, $width, $height, $arg0 = null, $arg1 = null, $arg2 = null)
		{
			$file_blob = DATA . 'blob/' . $blob;
			$thumb = $blob . '.thumb.' . $function . '-' . $width . 'x' . $height . '.jpg';
			$url_thumb = site()->url . 'data/blob/' . $thumb;
			$file_thumb = DATA . 'blob/' . $thumb;
	
			if (!is_file($file_thumb) || (filemtime($file_blob) > filemtime($file_thumb)))
			{
				if (!function_exists($function))
					return error('unknown method: ' . $function);
				$i = self::createFromFile($i);
				if (!$i)
					return null;
				$j = self::$function($i, $width, $height, $arg0, $arg1, $arg2);
				imagejpeg($j, $file_thumb);
				imagedestroy($i);
				imagedestroy($j);
			}
			return $url_thumb;
		}
	
		public static function watermarktransparent($image, $watermark, $alpha = 30, $position = 'center')
		{
			if (!is_resource($watermark))
			{
				if (is_string($watermark))
					$watermark_file = $watermark;
				else
				{
					$watermark_file = BASE . 'web/_images/watermark.gif';
					/*if (imagesx($image) >= 800)
						$watermark_file = $GLOBALS['site']['base'][0] . 'web/_images/watermark_700.gif';
					else
						$watermark_file = $GLOBALS['site']['base'][0] . 'web/_images/watermark_450.gif';*/
				}
				$watermark = imagecreatefromgif($watermark_file);
			}

			imagealphablending($watermark, true);
			imagealphablending($image, true);
			imagesavealpha($watermark, false);
			imagesavealpha($image, false);
			if ($position == 'top-left')
			{
				$x = 0;
				$y = 0;
			}
			else if ($position == 'top-right')
			{
				$x = (int) (imagesx($image) - imagesx($watermark));
				$y = 0;
			}
			else if ($position == 'bottom-left')
			{
				$x = 0;
				$y = (int) (imagesy($image) - imagesy($watermark));
			}
			else if ($position == 'bottom-right')
			{
				$x = (int) (imagesx($image) - imagesx($watermark));
				$y = (int) (imagesy($image) - imagesy($watermark));
			}
			else if ($position == 'center-stretch')
			{
				$watermarkOriginal = $watermark;
				if ((imagesx($image) < (imagesx($watermark))) || (imagesy($image) < (imagesy($watermark))))
				$watermark = imagescale($watermarkOriginal, imagesx($image), imagesy($image));
				$x = (int) ((imagesx($image) - imagesx($watermark)) / 2);
				$y = (int) ((imagesy($image) - imagesy($watermark)) / 2);
			}
			else /*($position == 'center')*/
			{
				$x = (int) ((imagesx($image) - imagesx($watermark)) / 2);
				$y = (int) ((imagesy($image) - imagesy($watermark)) / 2);
			}
			//imagecopy($image, $watermark, $x, $y, 0, 0, imagesx($watermark), imagesy($watermark));
			imagecopymerge($image, $watermark, $x, $y, 0, 0, imagesx($watermark), imagesy($watermark), $alpha);
			
			if (isset($watermark_file))
				imagedestroy($watermark);
		}
	}
?>

ACC SHELL 2018